From 764fa15e2415c9394d1064dc2256de33df691c12 Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Wed, 2 May 2018 23:03:37 +0200 Subject: [PATCH 1/2] dont shadow format passed in as function parameter --- public/app/features/templating/template_srv.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/app/features/templating/template_srv.ts b/public/app/features/templating/template_srv.ts index f6274a80165..e7c1dc7f102 100644 --- a/public/app/features/templating/template_srv.ts +++ b/public/app/features/templating/template_srv.ts @@ -179,16 +179,16 @@ export class TemplateSrv { return target; } - var variable, systemValue, value; + var variable, systemValue, value, fmt; this.regex.lastIndex = 0; return target.replace(this.regex, (match, var1, var2, fmt2, var3, fmt3) => { variable = this.index[var1 || var2 || var3]; - format = fmt2 || fmt3 || format; + fmt = fmt2 || fmt3 || format; if (scopedVars) { value = scopedVars[var1 || var2 || var3]; if (value) { - return this.formatValue(value.value, format, variable); + return this.formatValue(value.value, fmt, variable); } } @@ -198,7 +198,7 @@ export class TemplateSrv { systemValue = this.grafanaVariables[variable.current.value]; if (systemValue) { - return this.formatValue(systemValue, format, variable); + return this.formatValue(systemValue, fmt, variable); } value = variable.current.value; @@ -210,7 +210,7 @@ export class TemplateSrv { } } - var res = this.formatValue(value, format, variable); + var res = this.formatValue(value, fmt, variable); return res; }); } From a806f542c64a61cf41d7f9fc0620b6a69100100e Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Thu, 3 May 2018 18:42:58 +0200 Subject: [PATCH 2/2] test if default variable interpolation is effective when no specific format is specified --- .../app/features/templating/specs/template_srv.jest.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/public/app/features/templating/specs/template_srv.jest.ts b/public/app/features/templating/specs/template_srv.jest.ts index 5290a883c48..59915776b4f 100644 --- a/public/app/features/templating/specs/template_srv.jest.ts +++ b/public/app/features/templating/specs/template_srv.jest.ts @@ -136,6 +136,11 @@ describe('templateSrv', function() { var target = _templateSrv.replace('this=${test:pipe}', {}); 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() { @@ -164,6 +169,11 @@ describe('templateSrv', function() { var target = _templateSrv.replace('this.${test:glob}.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() {