Browse Source

fix(templating): fixed detection of nested template variables, fixes #5103

Torkel Ödegaard 9 years ago
parent
commit
2416ee04c8

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

@@ -97,8 +97,11 @@ function (angular, _) {
       if (!str) {
         return false;
       }
-      var match = this._regex.exec(str);
-      return match && (match[1] === variableName || match[2] === variableName);
+
+      variableName = regexEscape(variableName);
+      var findVarRegex = new RegExp('\\$(' + variableName + ')[\\W|$]|\\[\\[(' + variableName + ')\\]\\]', 'g');
+      var match = findVarRegex.exec(str);
+      return match !== null;
     };
 
     this.highlightVariablesAsHtml = function(str) {

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

@@ -200,6 +200,11 @@ define([
         expect(contains).to.be(true);
       });
 
+      it('should find it when part of segment', function() {
+        var contains = _templateSrv.containsVariable('metrics.$env.$group-*', 'group');
+        expect(contains).to.be(true);
+      });
+
     });
 
     describe('updateTemplateData with simple value', function() {