InfluxDB: Fix multi variable interpolation (#78068)

fix special variable escape
This commit is contained in:
ismail simsek
2023-11-14 15:59:34 +01:00
committed by GitHub
parent a221c1d754
commit 656808a41b
2 changed files with 23 additions and 2 deletions

View File

@@ -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);
});
});
});
});

View File

@@ -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;
}