Commit 1915d109 by Ivana Huckova Committed by GitHub

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

parent aae25c53
...@@ -502,6 +502,10 @@ describe('PrometheusDatasource', () => { ...@@ -502,6 +502,10 @@ describe('PrometheusDatasource', () => {
it('should return pipe separated values if the value is an array of strings', () => { 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)'); 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', () => { describe('and variable allows all', () => {
...@@ -516,6 +520,10 @@ describe('PrometheusDatasource', () => { ...@@ -516,6 +520,10 @@ describe('PrometheusDatasource', () => {
it('should return pipe separated values if the value is an array of strings', () => { 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)'); 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');
});
}); });
}); });
......
...@@ -159,6 +159,11 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions> ...@@ -159,6 +159,11 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
} }
const escapedValues = value.map(val => prometheusSpecialRegexEscape(val)); const escapedValues = value.map(val => prometheusSpecialRegexEscape(val));
if (escapedValues.length === 1) {
return escapedValues[0];
}
return '(' + escapedValues.join('|') + ')'; return '(' + escapedValues.join('|') + ')';
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment