mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
InfluxDB: Fix multi variable interpolation (#78068)
fix special variable escape
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user