Преглед изворни кода

fix(elasticsearch): quote variable value in lucene variable mulit format, fixes #2828

Torkel Ödegaard пре 10 година
родитељ
комит
a567939f78

+ 4 - 1
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('|');

+ 4 - 1
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': {

+ 1 - 1
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() {

+ 1 - 1
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\\\")');
       });
     });