From 656808a41bf6ac9f63a53e8680796643304345a4 Mon Sep 17 00:00:00 2001 From: ismail simsek Date: Tue, 14 Nov 2023 15:59:34 +0100 Subject: [PATCH] InfluxDB: Fix multi variable interpolation (#78068) fix special variable escape --- .../datasource/influxdb/datasource.test.ts | 18 +++++++++++++++++- .../plugins/datasource/influxdb/datasource.ts | 7 ++++++- 2 files changed, 23 insertions(+), 2 deletions(-) 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; }