diff --git a/public/app/plugins/datasource/influxdb/influx_query.ts b/public/app/plugins/datasource/influxdb/influx_query.ts index 6eb2d84aa49..cbdb61bca24 100644 --- a/public/app/plugins/datasource/influxdb/influx_query.ts +++ b/public/app/plugins/datasource/influxdb/influx_query.ts @@ -6,8 +6,8 @@ import queryPart from './query_part'; export default class InfluxQuery { target: any; selectModels: any[]; - groupByParts: any; queryBuilder: any; + groupByParts: any; constructor(target) { this.target = target; @@ -144,7 +144,7 @@ export default class InfluxQuery { // quote value unless regex if (operator !== '=~' && operator !== '!~') { - value = "'" + value + "'"; + value = "'" + value.replace('\\', '\\\\') + "'"; } return str + '"' + tag.key + '" ' + operator + ' ' + value; diff --git a/public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts b/public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts index be7afa16ab1..3893b8fbc2d 100644 --- a/public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts +++ b/public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts @@ -51,12 +51,12 @@ describe('InfluxQuery', function() { var query = new InfluxQuery({ measurement: 'cpu', groupBy: [{type: 'time', params: ['auto']}], - tags: [{key: 'hostname', value: 'server1'}] + tags: [{key: 'hostname', value: 'server\\1'}] }); var queryText = query.render(); - expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE "hostname" = \'server1\' AND $timeFilter' + expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE "hostname" = \'server\\\\1\' AND $timeFilter' + ' GROUP BY time($interval)'); });