From a567939f78e7eac8fd650f28913042818a652ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 28 Sep 2015 11:28:08 +0200 Subject: [PATCH] fix(elasticsearch): quote variable value in lucene variable mulit format, fixes #2828 --- public/app/features/templating/templateSrv.js | 5 ++++- public/app/features/templating/templateValuesSrv.js | 5 ++++- public/test/specs/templateSrv-specs.js | 2 +- public/test/specs/templateValuesSrv-specs.js | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/public/app/features/templating/templateSrv.js b/public/app/features/templating/templateSrv.js index 48aa4edde85..9a59510c6a4 100644 --- a/public/app/features/templating/templateSrv.js +++ b/public/app/features/templating/templateSrv.js @@ -44,7 +44,10 @@ function (angular, _) { return '(' + value.join('|') + ')'; } case "lucene": { - return '(' + value.join(' OR ') + ')'; + var quotedValues = _.map(value, function(val) { + return '\\\"' + val + '\\\"'; + }); + return '(' + quotedValues.join(' OR ') + ')'; } case "pipe": { return value.join('|'); diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index 5ec9ae85e4a..18216fabd0f 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -262,7 +262,10 @@ function (angular, _, kbn) { break; } case 'lucene': { - allValue = '(' + _.pluck(variable.options, 'text').join(' OR ') + ')'; + var quotedValues = _.map(variable.options, function(val) { + return '\\\"' + val.text + '\\\"'; + }); + allValue = '(' + quotedValues.join(' OR ') + ')'; break; } case 'regex values': { diff --git a/public/test/specs/templateSrv-specs.js b/public/test/specs/templateSrv-specs.js index 36f303e55c6..2b811244210 100644 --- a/public/test/specs/templateSrv-specs.js +++ b/public/test/specs/templateSrv-specs.js @@ -68,7 +68,7 @@ define([ value: ['test','test2'], } }); - expect(result).to.be('(test OR test2)'); + expect(result).to.be('(\\\"test\\\" OR \\\"test2\\\")'); }); it('multi value and regex format should render regex string', function() { diff --git a/public/test/specs/templateValuesSrv-specs.js b/public/test/specs/templateValuesSrv-specs.js index 4c5b7e19a69..e1e6fc347cb 100644 --- a/public/test/specs/templateValuesSrv-specs.js +++ b/public/test/specs/templateValuesSrv-specs.js @@ -321,7 +321,7 @@ define([ }); it('should add lucene glob', function() { - expect(scenario.variable.options[0].value).to.be('(backend1 OR backend2)'); + expect(scenario.variable.options[0].value).to.be('(\\\"backend1\\\" OR \\\"backend2\\\")'); }); });