Skip to content

Commit a567939

Browse files
committed
fix(elasticsearch): quote variable value in lucene variable mulit format, fixes grafana#2828
1 parent b80dc92 commit a567939

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

public/app/features/templating/templateSrv.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ function (angular, _) {
4444
return '(' + value.join('|') + ')';
4545
}
4646
case "lucene": {
47-
return '(' + value.join(' OR ') + ')';
47+
var quotedValues = _.map(value, function(val) {
48+
return '\\\"' + val + '\\\"';
49+
});
50+
return '(' + quotedValues.join(' OR ') + ')';
4851
}
4952
case "pipe": {
5053
return value.join('|');

public/app/features/templating/templateValuesSrv.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ function (angular, _, kbn) {
262262
break;
263263
}
264264
case 'lucene': {
265-
allValue = '(' + _.pluck(variable.options, 'text').join(' OR ') + ')';
265+
var quotedValues = _.map(variable.options, function(val) {
266+
return '\\\"' + val.text + '\\\"';
267+
});
268+
allValue = '(' + quotedValues.join(' OR ') + ')';
266269
break;
267270
}
268271
case 'regex values': {

public/test/specs/templateSrv-specs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ define([
6868
value: ['test','test2'],
6969
}
7070
});
71-
expect(result).to.be('(test OR test2)');
71+
expect(result).to.be('(\\\"test\\\" OR \\\"test2\\\")');
7272
});
7373

7474
it('multi value and regex format should render regex string', function() {

public/test/specs/templateValuesSrv-specs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ define([
321321
});
322322

323323
it('should add lucene glob', function() {
324-
expect(scenario.variable.options[0].value).to.be('(backend1 OR backend2)');
324+
expect(scenario.variable.options[0].value).to.be('(\\\"backend1\\\" OR \\\"backend2\\\")');
325325
});
326326
});
327327

0 commit comments

Comments
 (0)