From 6fab62739d9ca7b48c231fd546a19c8058805a40 Mon Sep 17 00:00:00 2001 From: ismail simsek Date: Tue, 27 Feb 2024 15:40:32 +0100 Subject: [PATCH] InfluxDB: Fix escaping template variable when it was used in parentheses (#83400) escape properly regardless of the parentheses --- .../plugins/datasource/influxdb/datasource.test.ts | 13 +++++++++++++ .../app/plugins/datasource/influxdb/datasource.ts | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/datasource.test.ts b/public/app/plugins/datasource/influxdb/datasource.test.ts index a5eb3beabab..5e20d38370a 100644 --- a/public/app/plugins/datasource/influxdb/datasource.test.ts +++ b/public/app/plugins/datasource/influxdb/datasource.test.ts @@ -443,6 +443,19 @@ describe('InfluxDataSource Frontend Mode', () => { expect(result).toBe(expectation); }); + it('should return the escaped value if the value wrapped in regex 3', () => { + const value = ['env', 'env2', 'env3']; + const variableMock = queryBuilder() + .withId('tempVar') + .withName('tempVar') + .withMulti(false) + .withIncludeAll(true) + .build(); + const result = ds.interpolateQueryExpr(value, variableMock, 'select from /^($tempVar)$/'); + const expectation = `env|env2|env3`; + expect(result).toBe(expectation); + }); + it('should **not** return the escaped value if the value **is not** wrapped in regex', () => { const value = '/special/path'; const variableMock = queryBuilder().withId('tempVar').withName('tempVar').withMulti(false).build(); diff --git a/public/app/plugins/datasource/influxdb/datasource.ts b/public/app/plugins/datasource/influxdb/datasource.ts index daa4e18ae8b..b3837a09871 100644 --- a/public/app/plugins/datasource/influxdb/datasource.ts +++ b/public/app/plugins/datasource/influxdb/datasource.ts @@ -316,8 +316,8 @@ export default class InfluxDatasource extends DataSourceWithBackend