Commit 6eba9c24 by Marcus Efraimsson Committed by GitHub

Merge pull request #11802 from svenklemm/variable-interpolation

dont shadow format passed in as function parameter in replace function in templatesrv
parents 8a9da4ba a806f542
...@@ -136,6 +136,11 @@ describe('templateSrv', function() { ...@@ -136,6 +136,11 @@ describe('templateSrv', function() {
var target = _templateSrv.replace('this=${test:pipe}', {}); var target = _templateSrv.replace('this=${test:pipe}', {});
expect(target).toBe('this=value1|value2'); expect(target).toBe('this=value1|value2');
}); });
it('should replace ${test:pipe} with piped value and $test with globbed value', function() {
var target = _templateSrv.replace('${test:pipe},$test', {}, 'glob');
expect(target).toBe('value1|value2,{value1,value2}');
});
}); });
describe('variable with all option', function() { describe('variable with all option', function() {
...@@ -164,6 +169,11 @@ describe('templateSrv', function() { ...@@ -164,6 +169,11 @@ describe('templateSrv', function() {
var target = _templateSrv.replace('this.${test:glob}.filters', {}); var target = _templateSrv.replace('this.${test:glob}.filters', {});
expect(target).toBe('this.{value1,value2}.filters'); expect(target).toBe('this.{value1,value2}.filters');
}); });
it('should replace ${test:pipe} with piped value and $test with globbed value', function() {
var target = _templateSrv.replace('${test:pipe},$test', {}, 'glob');
expect(target).toBe('value1|value2,{value1,value2}');
});
}); });
describe('variable with all option and custom value', function() { describe('variable with all option and custom value', function() {
......
...@@ -179,16 +179,16 @@ export class TemplateSrv { ...@@ -179,16 +179,16 @@ export class TemplateSrv {
return target; return target;
} }
var variable, systemValue, value; var variable, systemValue, value, fmt;
this.regex.lastIndex = 0; this.regex.lastIndex = 0;
return target.replace(this.regex, (match, var1, var2, fmt2, var3, fmt3) => { return target.replace(this.regex, (match, var1, var2, fmt2, var3, fmt3) => {
variable = this.index[var1 || var2 || var3]; variable = this.index[var1 || var2 || var3];
format = fmt2 || fmt3 || format; fmt = fmt2 || fmt3 || format;
if (scopedVars) { if (scopedVars) {
value = scopedVars[var1 || var2 || var3]; value = scopedVars[var1 || var2 || var3];
if (value) { if (value) {
return this.formatValue(value.value, format, variable); return this.formatValue(value.value, fmt, variable);
} }
} }
...@@ -198,7 +198,7 @@ export class TemplateSrv { ...@@ -198,7 +198,7 @@ export class TemplateSrv {
systemValue = this.grafanaVariables[variable.current.value]; systemValue = this.grafanaVariables[variable.current.value];
if (systemValue) { if (systemValue) {
return this.formatValue(systemValue, format, variable); return this.formatValue(systemValue, fmt, variable);
} }
value = variable.current.value; value = variable.current.value;
...@@ -210,7 +210,7 @@ export class TemplateSrv { ...@@ -210,7 +210,7 @@ export class TemplateSrv {
} }
} }
var res = this.formatValue(value, format, variable); var res = this.formatValue(value, fmt, variable);
return res; return res;
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment