mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Remove brackets from escaped value if just 1 value (#26995)
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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('|') + ')';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user