Skip to content

Commit

Permalink
Merge pull request buger#95 from HCHagen/master
Browse files Browse the repository at this point in the history
Return error rather than panicking on malformed json where there are …
  • Loading branch information
buger authored Jun 3, 2017
2 parents f4a8e0b + f86e085 commit 9fc8efe
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str
}

if maxPath >= level {
if level < 1 {
cb(-1, []byte{}, Unknown, MalformedJsonError)
return -1
}
pathsBuf[level-1] = bytesToString(&keyUnesc)

for pi, p := range paths {
Expand Down Expand Up @@ -345,6 +349,12 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str
case '[':
var arrIdxFlags int64
var pIdxFlags int64

if level < 0 {
cb(-1, []byte{}, Unknown, MalformedJsonError)
return -1
}

for pi, p := range paths {
if len(p) < level+1 || pathFlags&bitwiseFlags[pi+1] != 0 || p[level][0] != '[' || !sameTree(p, pathsBuf[:level]) {
continue
Expand Down

0 comments on commit 9fc8efe

Please sign in to comment.