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

* Templating: Allow percent encoding of variable with custom all

* Test fix
This commit is contained in:
Dominik Prokop 2023-03-27 09:35:41 +02:00 committed by GitHub
parent 3cfb7ac0dd
commit 2d7965402e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -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', () => {

View File

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