InfluxDB: Fix multi variable interpolation (#78068)

fix special variable escape
pull/78077/head^2
ismail simsek 2 years ago committed by GitHub
parent a221c1d754
commit 656808a41b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      public/app/plugins/datasource/influxdb/datasource.test.ts
  2. 7
      public/app/plugins/datasource/influxdb/datasource.ts

@ -7,7 +7,7 @@ import config from 'app/core/config';
import { TemplateSrv } from '../../../features/templating/template_srv'; import { TemplateSrv } from '../../../features/templating/template_srv';
import { BROWSER_MODE_DISABLED_MESSAGE } from './constants'; import { BROWSER_MODE_DISABLED_MESSAGE } from './constants';
import InfluxDatasource from './datasource'; import InfluxDatasource, { influxSpecialRegexEscape } from './datasource';
import { import {
getMockDSInstanceSettings, getMockDSInstanceSettings,
getMockInfluxDS, getMockInfluxDS,
@ -409,5 +409,21 @@ describe('InfluxDataSource Frontend Mode', () => {
expect(qData).toBe(qe); 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[]) { 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;
} }

Loading…
Cancel
Save