mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Fix quote stripping in parser (#87675)
* Prometheus: Fix quote stripping in parser Currently only double quotes are stripped from the end, while single quotes are left. Moreover, double quotes are stripped even when part of the value * Prometheus: Double escape the string, apply linting fixes for files that I touched
This commit is contained in:
parent
0ea2d6972f
commit
2bd95b2eb5
@ -746,6 +746,43 @@ describe('buildVisualQueryFromString', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('strips enclosing quotes', () => {
|
||||
expect(buildVisualQueryFromString("counters_logins{app='frontend', host=`localhost`}")).toEqual(
|
||||
noErrors({
|
||||
metric: 'counters_logins',
|
||||
labels: [
|
||||
{
|
||||
op: '=',
|
||||
value: 'frontend',
|
||||
label: 'app',
|
||||
},
|
||||
{
|
||||
op: '=',
|
||||
value: 'localhost',
|
||||
label: 'host',
|
||||
},
|
||||
],
|
||||
operations: [],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('leaves escaped quotes inside string', () => {
|
||||
expect(buildVisualQueryFromString('counters_logins{app="fron\\"\\"tend"}')).toEqual(
|
||||
noErrors({
|
||||
metric: 'counters_logins',
|
||||
labels: [
|
||||
{
|
||||
op: '=',
|
||||
value: 'fron\\"\\"tend',
|
||||
label: 'app',
|
||||
},
|
||||
],
|
||||
operations: [],
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function noErrors(query: PromVisualQuery) {
|
||||
|
@ -205,7 +205,7 @@ function isIntervalVariableError(node: SyntaxNode) {
|
||||
function getLabel(expr: string, node: SyntaxNode): QueryBuilderLabelFilter {
|
||||
const label = getString(expr, node.getChild(LabelName));
|
||||
const op = getString(expr, node.getChild(MatchOp));
|
||||
const value = getString(expr, node.getChild(StringLiteral)).replace(/"/g, '');
|
||||
const value = getString(expr, node.getChild(StringLiteral)).replace(/^["'`]|["'`]$/g, '');
|
||||
return {
|
||||
label,
|
||||
op,
|
||||
|
Loading…
Reference in New Issue
Block a user