浏览代码

fix(templating): improved detection of nested template variables, fixes #4986, fixes #4987

Torkel Ödegaard 9 年之前
父节点
当前提交
35f55cabf0
共有 3 个文件被更改,包括 8 次插入1 次删除
  1. 1 0
      CHANGELOG.md
  2. 2 1
      public/app/features/templating/templateSrv.js
  3. 5 0
      public/test/specs/templateSrv-specs.js

+ 1 - 0
CHANGELOG.md

@@ -1,6 +1,7 @@
 # 3.0.2 Stable (unreleased)
 
 * **Templating**: Fixed issue mixing row repeat and panel repeats, fixes [#4988](https://github.com/grafana/grafana/issues/4988)
+* **Templating**: Fixed issue detecting dependencies in nested variables, fixes [#4987](https://github.com/grafana/grafana/issues/4987), fixes [#4986](https://github.com/grafana/grafana/issues/4986)
 
 # 3.0.1 Stable (2016-05-11)
 

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

@@ -97,7 +97,8 @@ function (angular, _) {
       if (!str) {
         return false;
       }
-      return str.indexOf('$' + variableName) !== -1 || str.indexOf('[[' + variableName + ']]') !== -1;
+      var match = this._regex.exec(str);
+      return match && (match[1] === variableName || match[2] === variableName);
     };
 
     this.highlightVariablesAsHtml = function(str) {

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

@@ -190,6 +190,11 @@ define([
         expect(contains).to.be(true);
       });
 
+      it('should not find it if only part matches with $var syntax', function() {
+        var contains = _templateSrv.containsVariable('this.$ServerDomain.filters', 'Server');
+        expect(contains).to.be(false);
+      });
+
       it('should find it with [[var]] syntax', function() {
         var contains = _templateSrv.containsVariable('this.[[test]].filters', 'test');
         expect(contains).to.be(true);