Commit de90ad89 by Torkel Ödegaard

feat(influxdb): escape influxdb tag values, fixes #3950

parent 7f83be3d
...@@ -6,8 +6,8 @@ import queryPart from './query_part'; ...@@ -6,8 +6,8 @@ import queryPart from './query_part';
export default class InfluxQuery { export default class InfluxQuery {
target: any; target: any;
selectModels: any[]; selectModels: any[];
groupByParts: any;
queryBuilder: any; queryBuilder: any;
groupByParts: any;
constructor(target) { constructor(target) {
this.target = target; this.target = target;
...@@ -144,7 +144,7 @@ export default class InfluxQuery { ...@@ -144,7 +144,7 @@ export default class InfluxQuery {
// quote value unless regex // quote value unless regex
if (operator !== '=~' && operator !== '!~') { if (operator !== '=~' && operator !== '!~') {
value = "'" + value + "'"; value = "'" + value.replace('\\', '\\\\') + "'";
} }
return str + '"' + tag.key + '" ' + operator + ' ' + value; return str + '"' + tag.key + '" ' + operator + ' ' + value;
......
...@@ -51,12 +51,12 @@ describe('InfluxQuery', function() { ...@@ -51,12 +51,12 @@ describe('InfluxQuery', function() {
var query = new InfluxQuery({ var query = new InfluxQuery({
measurement: 'cpu', measurement: 'cpu',
groupBy: [{type: 'time', params: ['auto']}], groupBy: [{type: 'time', params: ['auto']}],
tags: [{key: 'hostname', value: 'server1'}] tags: [{key: 'hostname', value: 'server\\1'}]
}); });
var queryText = query.render(); 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)'); + ' GROUP BY time($interval)');
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment