Skip to content

Commit 9fc8efe

Browse files
authored
Merge pull request #95 from HCHagen/master
Return error rather than panicking on malformed json where there are …
2 parents f4a8e0b + f86e085 commit 9fc8efe

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

parser.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str
295295
}
296296

297297
if maxPath >= level {
298+
if level < 1 {
299+
cb(-1, []byte{}, Unknown, MalformedJsonError)
300+
return -1
301+
}
298302
pathsBuf[level-1] = bytesToString(&keyUnesc)
299303

300304
for pi, p := range paths {
@@ -345,6 +349,12 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str
345349
case '[':
346350
var arrIdxFlags int64
347351
var pIdxFlags int64
352+
353+
if level < 0 {
354+
cb(-1, []byte{}, Unknown, MalformedJsonError)
355+
return -1
356+
}
357+
348358
for pi, p := range paths {
349359
if len(p) < level+1 || pathFlags&bitwiseFlags[pi+1] != 0 || p[level][0] != '[' || !sameTree(p, pathsBuf[:level]) {
350360
continue

0 commit comments

Comments
 (0)