From 0daadc954c189d2f2b1d1c67f1959262a2ca7a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 25 May 2016 10:46:35 +0200 Subject: [PATCH] fix(templating): fixed issue with detecting data source variable in other template variable definition, fixes #5165 --- public/app/features/templating/templateSrv.js | 2 +- public/test/specs/templateSrv-specs.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/public/app/features/templating/templateSrv.js b/public/app/features/templating/templateSrv.js index 2e5f945c96a..b8d6cbaee2d 100644 --- a/public/app/features/templating/templateSrv.js +++ b/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; }; diff --git a/public/test/specs/templateSrv-specs.js b/public/test/specs/templateSrv-specs.js index c5f33d4f72f..a592cc7a152 100644 --- a/public/test/specs/templateSrv-specs.js +++ b/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() {