Skip to content

Commit 35f55ca

Browse files
committed
fix(templating): improved detection of nested template variables, fixes grafana#4986, fixes grafana#4987
1 parent 0201ac2 commit 35f55ca

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 3.0.2 Stable (unreleased)
22

33
* **Templating**: Fixed issue mixing row repeat and panel repeats, fixes [#4988](https://github.com/grafana/grafana/issues/4988)
4+
* **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)
45

56
# 3.0.1 Stable (2016-05-11)
67

public/app/features/templating/templateSrv.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ function (angular, _) {
9797
if (!str) {
9898
return false;
9999
}
100-
return str.indexOf('$' + variableName) !== -1 || str.indexOf('[[' + variableName + ']]') !== -1;
100+
var match = this._regex.exec(str);
101+
return match && (match[1] === variableName || match[2] === variableName);
101102
};
102103

103104
this.highlightVariablesAsHtml = function(str) {

public/test/specs/templateSrv-specs.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ define([
190190
expect(contains).to.be(true);
191191
});
192192

193+
it('should not find it if only part matches with $var syntax', function() {
194+
var contains = _templateSrv.containsVariable('this.$ServerDomain.filters', 'Server');
195+
expect(contains).to.be(false);
196+
});
197+
193198
it('should find it with [[var]] syntax', function() {
194199
var contains = _templateSrv.containsVariable('this.[[test]].filters', 'test');
195200
expect(contains).to.be(true);

0 commit comments

Comments
 (0)