mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 13:09:22 -06:00
Loki: Fix parsing of escaped quotes in LogQL (#69584)
* fix parsing issue * replace escaped quotes
This commit is contained in:
parent
807c7d5b01
commit
a81cee1d05
@ -76,6 +76,36 @@ describe('buildVisualQueryFromString', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('parses query with line filter and escaped quote', () => {
|
||||
expect(buildVisualQueryFromString('{app="frontend"} |= "\\"line"')).toEqual(
|
||||
noErrors({
|
||||
labels: [
|
||||
{
|
||||
op: '=',
|
||||
value: 'frontend',
|
||||
label: 'app',
|
||||
},
|
||||
],
|
||||
operations: [{ id: LokiOperationId.LineContains, params: ['"line'] }],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('parses query with label filter and escaped quote', () => {
|
||||
expect(buildVisualQueryFromString('{app="frontend"} | bar="\\"baz"')).toEqual(
|
||||
noErrors({
|
||||
labels: [
|
||||
{
|
||||
op: '=',
|
||||
value: 'frontend',
|
||||
label: 'app',
|
||||
},
|
||||
],
|
||||
operations: [{ id: LokiOperationId.LabelFilter, params: ['bar', '=', '"baz'] }],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('returns error for query with ip matching line filter', () => {
|
||||
const context = buildVisualQueryFromString('{app="frontend"} |= ip("192.168.4.5/16") | logfmt');
|
||||
expect(context).toEqual(
|
||||
@ -320,7 +350,7 @@ describe('buildVisualQueryFromString', () => {
|
||||
});
|
||||
|
||||
it('parses query with with decolorize and other operations', () => {
|
||||
expect(buildVisualQueryFromString('{app="frontend"} | logfmt | decolorize | __error__="')).toEqual(
|
||||
expect(buildVisualQueryFromString('{app="frontend"} | logfmt | decolorize | __error__=""')).toEqual(
|
||||
noErrors({
|
||||
labels: [
|
||||
{
|
||||
|
@ -599,7 +599,10 @@ function isIntervalVariableError(node: SyntaxNode) {
|
||||
|
||||
function handleQuotes(string: string) {
|
||||
if (string[0] === `"` && string[string.length - 1] === `"`) {
|
||||
return string.replace(/"/g, '').replace(/\\\\/g, '\\');
|
||||
return string
|
||||
.substring(1, string.length - 1)
|
||||
.replace(/\\"/g, '"')
|
||||
.replace(/\\\\/g, '\\');
|
||||
}
|
||||
return string.replace(/`/g, '');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user