From 2d7965402e38f94406e370b6a7e58437719a309c Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Mon, 27 Mar 2023 09:35:41 +0200 Subject: [PATCH] Templating: Allow percent encoding of variable with custom all (#65266) * Templating: Allow percent encoding of variable with custom all * Test fix --- .../features/templating/template_srv.test.ts | 19 +++++++++++++++++++ .../app/features/templating/template_srv.ts | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/public/app/features/templating/template_srv.test.ts b/public/app/features/templating/template_srv.test.ts index 1d9459c35f3..a4498ee3225 100644 --- a/public/app/features/templating/template_srv.test.ts +++ b/public/app/features/templating/template_srv.test.ts @@ -309,6 +309,25 @@ describe('templateSrv', () => { const target = _templateSrv.replace('${test:queryparam}', {}); expect(target).toBe('var-test=All'); }); + + describe('percentencode option', () => { + beforeEach(() => { + _templateSrv = initTemplateSrv(key, [ + { + type: 'query', + name: 'test', + current: { value: '$__all' }, + allValue: '.+', + options: [{ value: 'value1' }, { value: 'value2' }], + }, + ]); + }); + + it('should respect percentencode format', () => { + const target = _templateSrv.replace('this.${test:percentencode}', {}, 'regex'); + expect(target).toBe('this..%2B'); + }); + }); }); describe('lucene format', () => { diff --git a/public/app/features/templating/template_srv.ts b/public/app/features/templating/template_srv.ts index f42a11162ef..4ecd56515be 100644 --- a/public/app/features/templating/template_srv.ts +++ b/public/app/features/templating/template_srv.ts @@ -332,8 +332,8 @@ export class TemplateSrv implements BaseTemplateSrv { if (this.isAllValue(value)) { value = this.getAllValue(variable); text = ALL_VARIABLE_TEXT; - // skip formatting of custom all values - if (variable.allValue && fmt !== FormatRegistryID.text) { + // skip formatting of custom all values unless format set to text or percentencode + if (variable.allValue && fmt !== FormatRegistryID.text && fmt !== FormatRegistryID.percentEncode) { return this.replace(value); } }