mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 08:56:43 -06:00
influxdb: influxql query editor: fix escaping problematic characters (#39170)
This commit is contained in:
parent
ad971cc9be
commit
27e3fda7ce
@ -142,6 +142,7 @@ export default class InfluxQueryModel {
|
||||
}
|
||||
|
||||
private renderTagCondition(tag: InfluxQueryTag, index: number, interpolate?: boolean) {
|
||||
// FIXME: merge this function with query_builder/renderTagCondition
|
||||
let str = '';
|
||||
let operator = tag.operator;
|
||||
let value = tag.value;
|
||||
|
@ -2,6 +2,7 @@ import { reduce } from 'lodash';
|
||||
import kbn from 'app/core/utils/kbn';
|
||||
|
||||
function renderTagCondition(tag: { operator: any; value: string; condition: any; key: string }, index: number) {
|
||||
// FIXME: merge this function with influx_query_model/renderTagCondition
|
||||
let str = '';
|
||||
let operator = tag.operator;
|
||||
let value = tag.value;
|
||||
@ -19,7 +20,7 @@ function renderTagCondition(tag: { operator: any; value: string; condition: any;
|
||||
|
||||
// quote value unless regex or number, or if empty-string
|
||||
if (value === '' || (operator !== '=~' && operator !== '!~' && isNaN(+value))) {
|
||||
value = "'" + value + "'";
|
||||
value = "'" + value.replace(/\\/g, '\\\\').replace(/\'/g, "\\'") + "'";
|
||||
}
|
||||
|
||||
return str + '"' + tag.key + '" ' + operator + ' ' + value;
|
||||
|
@ -178,6 +178,24 @@ describe('InfluxQueryBuilder', () => {
|
||||
expect(query).toBe(`SHOW TAG KEYS WHERE "app" == 42`);
|
||||
});
|
||||
|
||||
it('should handle tag-value-contains-backslash-character getting tag-keys', () => {
|
||||
const builder = new InfluxQueryBuilder(
|
||||
{ measurement: undefined, tags: [{ key: 'app', value: 'lab\\el', operator: '==' }] },
|
||||
undefined
|
||||
);
|
||||
const query = builder.buildExploreQuery('TAG_KEYS');
|
||||
expect(query).toBe(`SHOW TAG KEYS WHERE "app" == 'lab\\\\el'`);
|
||||
});
|
||||
|
||||
it('should handle tag-value-contains-single-quote-character getting tag-keys', () => {
|
||||
const builder = new InfluxQueryBuilder(
|
||||
{ measurement: undefined, tags: [{ key: 'app', value: "lab'el", operator: '==' }] },
|
||||
undefined
|
||||
);
|
||||
const query = builder.buildExploreQuery('TAG_KEYS');
|
||||
expect(query).toBe(`SHOW TAG KEYS WHERE "app" == 'lab\\'el'`);
|
||||
});
|
||||
|
||||
it('should handle tag-value=emptry-string when getting measurements', () => {
|
||||
const builder = new InfluxQueryBuilder(
|
||||
{ measurement: undefined, tags: [{ key: 'app', value: '', operator: '==' }] },
|
||||
|
Loading…
Reference in New Issue
Block a user