Templating: Allow percent encoding of variable with custom all (#65266)

* Templating: Allow percent encoding of variable with custom all

* Test fix
pull/65161/head^2
Dominik Prokop 2 years ago committed by GitHub
parent 3cfb7ac0dd
commit 2d7965402e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      public/app/features/templating/template_srv.test.ts
  2. 4
      public/app/features/templating/template_srv.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', () => {

@ -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);
}
}

Loading…
Cancel
Save