diff --git a/public/app/plugins/datasource/influxdb/datasource.test.ts b/public/app/plugins/datasource/influxdb/datasource.test.ts index be4d4a53c68..c66320737b3 100644 --- a/public/app/plugins/datasource/influxdb/datasource.test.ts +++ b/public/app/plugins/datasource/influxdb/datasource.test.ts @@ -7,7 +7,7 @@ import config from 'app/core/config'; import { TemplateSrv } from '../../../features/templating/template_srv'; import { BROWSER_MODE_DISABLED_MESSAGE } from './constants'; -import InfluxDatasource from './datasource'; +import InfluxDatasource, { influxSpecialRegexEscape } from './datasource'; import { getMockDSInstanceSettings, getMockInfluxDS, @@ -409,5 +409,21 @@ describe('InfluxDataSource Frontend Mode', () => { expect(qData).toBe(qe); }); }); + + describe('influxSpecialRegexEscape', () => { + it('should escape the dot properly', () => { + const value = 'value.with-dot'; + const expectation = `value\.with-dot`; + const result = influxSpecialRegexEscape(value); + expect(result).toBe(expectation); + }); + + it('should escape the url properly', () => { + const value = 'https://aaaa-aa-aaa.bbb.ccc.ddd:8443/jolokia'; + const expectation = `https:\/\/aaaa-aa-aaa\.bbb\.ccc\.ddd:8443\/jolokia`; + const result = influxSpecialRegexEscape(value); + expect(result).toBe(expectation); + }); + }); }); }); diff --git a/public/app/plugins/datasource/influxdb/datasource.ts b/public/app/plugins/datasource/influxdb/datasource.ts index 18805064d9f..2217b4fe153 100644 --- a/public/app/plugins/datasource/influxdb/datasource.ts +++ b/public/app/plugins/datasource/influxdb/datasource.ts @@ -793,5 +793,10 @@ export function influxRegularEscape(value: string | string[]) { } export function influxSpecialRegexEscape(value: string | string[]) { - return typeof value === 'string' ? value.replace(/\\/g, '\\\\\\\\').replace(/[$^*{}\[\]\'+?.()|]/g, '\\\\$&') : value; + if (typeof value !== 'string') { + return value; + } + value = value.replace(/\\/g, '\\\\\\\\'); + value = value.replace(/[$^*{}\[\]\'+?.()|]/g, '$&'); + return value; }