Просмотр исходного кода

fix(templating): fixed issue with detecting data source variable in other template variable definition, fixes #5165

Torkel Ödegaard 9 лет назад
Родитель
Сommit
0daadc954c

+ 1 - 1
public/app/features/templating/templateSrv.js

@@ -103,7 +103,7 @@ function (angular, _) {
       }
 
       variableName = regexEscape(variableName);
-      var findVarRegex = new RegExp('\\$(' + variableName + ')[\\W|$]|\\[\\[(' + variableName + ')\\]\\]', 'g');
+      var findVarRegex = new RegExp('\\$(' + variableName + ')(?:\\W|$)|\\[\\[(' + variableName + ')\\]\\]', 'g');
       var match = findVarRegex.exec(str);
       return match !== null;
     };

+ 4 - 0
public/test/specs/templateSrv-specs.js

@@ -205,6 +205,10 @@ define([
         expect(contains).to.be(true);
       });
 
+      it('should find it its the only thing', function() {
+        var contains = _templateSrv.containsVariable('$env', 'env');
+        expect(contains).to.be(true);
+      });
     });
 
     describe('updateTemplateData with simple value', function() {