Remove brackets from escaped value if just 1 value (#26995)

This commit is contained in:
Ivana Huckova
2020-08-13 19:15:34 +02:00
committed by GitHub
parent aae25c5308
commit 1915d10980
2 changed files with 13 additions and 0 deletions

View File

@@ -502,6 +502,10 @@ describe('PrometheusDatasource', () => {
it('should return pipe separated values if the value is an array of strings', () => {
expect(ds.interpolateQueryExpr(['a|bc', 'de|f'], customVariable)).toEqual('(a\\\\|bc|de\\\\|f)');
});
it('should return 1 regex escaped value if there is just 1 value in an array of strings', () => {
expect(ds.interpolateQueryExpr(['looking*glass'], customVariable)).toEqual('looking\\\\*glass');
});
});
describe('and variable allows all', () => {
@@ -516,6 +520,10 @@ describe('PrometheusDatasource', () => {
it('should return pipe separated values if the value is an array of strings', () => {
expect(ds.interpolateQueryExpr(['a|bc', 'de|f'], customVariable)).toEqual('(a\\\\|bc|de\\\\|f)');
});
it('should return 1 regex escaped value if there is just 1 value in an array of strings', () => {
expect(ds.interpolateQueryExpr(['looking*glass'], customVariable)).toEqual('looking\\\\*glass');
});
});
});

View File

@@ -159,6 +159,11 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
}
const escapedValues = value.map(val => prometheusSpecialRegexEscape(val));
if (escapedValues.length === 1) {
return escapedValues[0];
}
return '(' + escapedValues.join('|') + ')';
}