Skip to content

Commit

Permalink
fix issue 188 (#192)
Browse files Browse the repository at this point in the history
**Description**: This pr fix issue #188. If `findKeyStart` meets a `[` or `{`, it should not add i with `blockEnd`’s return value directly because it may return -1 if it did not find the close symbol
  • Loading branch information
AllenX2018 committed Mar 21, 2020
1 parent 1a29609 commit 91ac968
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ func findKeyStart(data []byte, key string) (int, error) {
}

case '[':
i = blockEnd(data[i:], data[i], ']') + i
end := blockEnd(data[i:], data[i], ']')
if end != -1 {
i = i + end
}
case '{':
i = blockEnd(data[i:], data[i], '}') + i
end := blockEnd(data[i:], data[i], '}')
if end != -1 {
i = i + end
}
}
i++
}
Expand Down
12 changes: 12 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ var deleteTests = []DeleteTest{
path: []string{"b"},
data: `{"a": "1" , "c": 3}`,
},
{
desc: "Issue #188: infinite loop in Delete",
json: `^_�^C^A^@[`,
path: []string{""},
data: `^_�^C^A^@[`,
},
{
desc: "Issue #188: infinite loop in Delete",
json: `^_�^C^A^@{`,
path: []string{""},
data: `^_�^C^A^@{`,
},
}

var setTests = []SetTest{
Expand Down

0 comments on commit 91ac968

Please # to comment.