Skip to content

Commit f86e085

Browse files
author
HC Hagen
committed
Return error rather than panicking on malformed json where there are more closing brackets than opening brackets
1 parent 25663cd commit f86e085

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

parser.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str
343343
case '[':
344344
var arrIdxFlags int64
345345
var pIdxFlags int64
346+
347+
if level < 0 {
348+
cb(-1, []byte{}, Unknown, MalformedJsonError)
349+
return -1
350+
}
351+
346352
for pi, p := range paths {
347353
if len(p) < level+1 || pathFlags&bitwiseFlags[pi+1] != 0 || p[level][0] != '[' || !sameTree(p, pathsBuf[:level]) {
348354
continue

0 commit comments

Comments
 (0)