Skip to content

Commit

Permalink
Merge pull request buger#97 from jensenak/bugfix-recursive-object-index
Browse files Browse the repository at this point in the history
Bugfix recursive object index
  • Loading branch information
buger authored Mar 25, 2017
2 parents 7266f2b + 4b6934c commit 016ea00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ func searchKeys(data []byte, keys ...string) int {
if valueFound == nil {
return -1
} else {
return i + valueOffset + searchKeys(valueFound, keys[level+1:]...)
subIndex := searchKeys(valueFound, keys[level+1:]...)
if subIndex < 0 {
return -1
}
return i + valueOffset + subIndex
}
} else {
// Do not search for keys inside arrays
Expand Down
14 changes: 13 additions & 1 deletion parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,19 @@ var getTests = []GetTest{
path: []string{"b"},
isFound: false,
},

{ // Issue #81
desc: `missing key in object in array`,
json: `{"p":{"a":[{"u":"abc","t":"th"}]}}`,
path: []string{"p", "a", "[0]", "x"},
isFound: false,
},
{ // Issue #81 counter test
desc: `existing key in object in array`,
json: `{"p":{"a":[{"u":"abc","t":"th"}]}}`,
path: []string{"p", "a", "[0]", "u"},
isFound: true,
data: "abc",
},
{ // This test returns not found instead of a parse error, as checking for the malformed JSON would reduce performance
desc: "malformed key (followed by comma followed by colon)",
json: `{"a",:1}`,
Expand Down

0 comments on commit 016ea00

Please sign in to comment.