Skip to content

Commit 0c71f93

Browse files
committed
fix(logql): Fix panic in json parsing when using invalid array index
This PR fixes a panic that occurs with the following json parser expression: ``` | json keys[""] ``` when the log line is the following: ```json {"keys": ["a", "b", "c"]} ``` Signed-off-by: Christian Haudum <[email protected]>
1 parent 39b57ec commit 0c71f93

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

pkg/logql/log/parser_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,26 @@ func TestJSONExpressionParser(t *testing.T) {
368368
labels.FromStrings("param", "1"),
369369
NoParserHints(),
370370
},
371+
{
372+
"object element not present",
373+
testLine,
374+
[]LabelExtractionExpr{
375+
NewLabelExtractionExpr("undefined", `pod[""]`),
376+
},
377+
labels.EmptyLabels(),
378+
labels.FromStrings("undefined", ""),
379+
NoParserHints(),
380+
},
381+
{
382+
"accessing invalid array index",
383+
testLine,
384+
[]LabelExtractionExpr{
385+
NewLabelExtractionExpr("param", `pod.deployment.params[""]`),
386+
},
387+
labels.EmptyLabels(),
388+
labels.FromStrings("param", ""),
389+
NoParserHints(),
390+
},
371391
{
372392
"array string element",
373393
testLine,

vendor/github.com/grafana/jsonparser/parser.go

+1-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)