diff --git a/go.mod b/go.mod index 32cae2cba59d..c003fd8813f9 100644 --- a/go.mod +++ b/go.mod @@ -125,7 +125,7 @@ require ( github.com/efficientgo/core v1.0.0-rc.3 github.com/fsnotify/fsnotify v1.7.0 github.com/gogo/googleapis v1.4.1 - github.com/grafana/jsonparser v0.0.0-20240425183733-ea80629e1a32 + github.com/grafana/jsonparser v0.0.0-20241004153430-023329977675 github.com/grafana/loki/pkg/push v0.0.0-20240924133635-758364c7775f github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/hashicorp/raft v1.7.1 diff --git a/go.sum b/go.sum index 00afdeb6e123..ce616ba23be6 100644 --- a/go.sum +++ b/go.sum @@ -1052,8 +1052,8 @@ github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85 h1:xLuzPoOzdfNb/RF/I github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85/go.mod h1:crI9WX6p0IhrqB+DqIUHulRW853PaNFf7o4UprV//3I= github.com/grafana/gomemcache v0.0.0-20240229205252-cd6a66d6fb56 h1:X8IKQ0wu40wpvYcKfBcc5T4QnhdQjUhtUtB/1CY89lE= github.com/grafana/gomemcache v0.0.0-20240229205252-cd6a66d6fb56/go.mod h1:PGk3RjYHpxMM8HFPhKKo+vve3DdlPUELZLSDEFehPuU= -github.com/grafana/jsonparser v0.0.0-20240425183733-ea80629e1a32 h1:NznuPwItog+rwdVg8hAuGKP29ndRSzJAwhxKldkP8oQ= -github.com/grafana/jsonparser v0.0.0-20240425183733-ea80629e1a32/go.mod h1:796sq+UcONnSlzA3RtlBZ+b/hrerkZXiEmO8oMjyRwY= +github.com/grafana/jsonparser v0.0.0-20241004153430-023329977675 h1:U94jQ2TQr1m3HNyE8efSdyaBbDrdPaWImXyenuKZ/nw= +github.com/grafana/jsonparser v0.0.0-20241004153430-023329977675/go.mod h1:796sq+UcONnSlzA3RtlBZ+b/hrerkZXiEmO8oMjyRwY= github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe h1:yIXAAbLswn7VNWBIvM71O2QsgfgW9fRXZNR0DXe6pDU= github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= github.com/grafana/pyroscope-go/godeltaprof v0.1.8 h1:iwOtYXeeVSAeYefJNaxDytgjKtUuKQbJqgAIjlnicKg= diff --git a/pkg/logql/log/parser_test.go b/pkg/logql/log/parser_test.go index 28989b7cb5fe..fd08467af858 100644 --- a/pkg/logql/log/parser_test.go +++ b/pkg/logql/log/parser_test.go @@ -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, diff --git a/vendor/github.com/grafana/jsonparser/parser.go b/vendor/github.com/grafana/jsonparser/parser.go index 5df2a463dcee..9958ab4ee531 100644 --- a/vendor/github.com/grafana/jsonparser/parser.go +++ b/vendor/github.com/grafana/jsonparser/parser.go @@ -512,10 +512,10 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str } for pi, p := range paths { - if len(p) < level+1 || pathFlags[pi] || p[level][0] != '[' || !sameTree(p, pathsBuf[:level]) { + if len(p) < level+1 || pathFlags[pi] || p[level] == "" || p[level][0] != '[' || !sameTree(p, pathsBuf[:level]) { continue } - if len(p[level]) >= 2 { + if len(p[level]) > 2 { aIdx, _ := strconv.Atoi(p[level][1 : len(p[level])-1]) arrIdxFlags[aIdx] = x pIdxFlags[pi] = true @@ -712,12 +712,10 @@ func WriteToBuffer(buffer []byte, str string) int { } /* - Del - Receives existing data structure, path to delete. Returns: `data` - return modified data - */ func Delete(data []byte, keys ...string) []byte { lk := len(keys) @@ -798,13 +796,11 @@ func Delete(data []byte, keys ...string) []byte { } /* - Set - Receives existing data structure, path to set, and data to set at that key. Returns: `value` - modified byte array `err` - On any parsing error - */ func Set(data []byte, setValue []byte, keys ...string) (value []byte, err error) { // ensure keys are set diff --git a/vendor/modules.txt b/vendor/modules.txt index 4e50c0c98bde..bc92b7462c8e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1037,7 +1037,7 @@ github.com/grafana/go-gelf/v2/gelf # github.com/grafana/gomemcache v0.0.0-20240229205252-cd6a66d6fb56 ## explicit; go 1.18 github.com/grafana/gomemcache/memcache -# github.com/grafana/jsonparser v0.0.0-20240425183733-ea80629e1a32 +# github.com/grafana/jsonparser v0.0.0-20241004153430-023329977675 ## explicit; go 1.13 github.com/grafana/jsonparser # github.com/grafana/loki/pkg/push v0.0.0-20240924133635-758364c7775f => ./pkg/push