Skip to content

Commit

Permalink
fix(logql): Fix panic in json parsing when using invalid array index
Browse files Browse the repository at this point in the history
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 <christian.haudum@gmail.com>
  • Loading branch information
chaudum committed Oct 4, 2024
1 parent 39b57ec commit 0c71f93
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 20 additions & 0 deletions pkg/logql/log/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,26 @@ func TestJSONExpressionParser(t *testing.T) {
labels.FromStrings("param", "1"),
NoParserHints(),
},
{
"object element not present",
testLine,
[]LabelExtractionExpr{
NewLabelExtractionExpr("undefined", `pod[""]`),
},
labels.EmptyLabels(),
labels.FromStrings("undefined", ""),
NoParserHints(),
},
{
"accessing invalid array index",
testLine,
[]LabelExtractionExpr{
NewLabelExtractionExpr("param", `pod.deployment.params[""]`),
},
labels.EmptyLabels(),
labels.FromStrings("param", ""),
NoParserHints(),
},
{
"array string element",
testLine,
Expand Down
6 changes: 1 addition & 5 deletions vendor/github.com/grafana/jsonparser/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0c71f93

Please sign in to comment.