From 35f55cabf0d8ed2fd24d07d07de0a7e398e24d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 12 May 2016 10:41:15 +0200 Subject: [PATCH] fix(templating): improved detection of nested template variables, fixes #4986, fixes #4987 --- CHANGELOG.md | 1 + public/app/features/templating/templateSrv.js | 3 ++- public/test/specs/templateSrv-specs.js | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd2a4dd50a1..e9beca0c761 100644 --- a/CHANGELOG.md +++ b/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) diff --git a/public/app/features/templating/templateSrv.js b/public/app/features/templating/templateSrv.js index f60414eac43..7e96af22e2a 100644 --- a/public/app/features/templating/templateSrv.js +++ b/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) { diff --git a/public/test/specs/templateSrv-specs.js b/public/test/specs/templateSrv-specs.js index 3334d7a7bfe..fd7247cbd81 100644 --- a/public/test/specs/templateSrv-specs.js +++ b/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);