瀏覽代碼

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

Torkel Ödegaard 9 年之前
父節點
當前提交
0daadc954c
共有 2 個文件被更改,包括 5 次插入1 次删除
  1. 1 1
      public/app/features/templating/templateSrv.js
  2. 4 0
      public/test/specs/templateSrv-specs.js

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