Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Gurov committed Dec 24, 2019
1 parent da02ec7 commit 882a55f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ ok github.com/bhmj/jsonslice 83.152s

## Changelog

**0.1.3** (2019-12-24) -- bugfix: `$[0].foo` `[{"foo":"\\"}]` generated "unexpected end of input"

**0.1.2** (2019-12-07) -- nested aggregation (`$[:].['a','b']`) now works as expected. TODO: add option to switch nested aggregation mode at runtime!

**0.1.1** (2019-12-01) -- "not equal" regexp operator added (`!=~` or `!~`).
Expand Down
13 changes: 8 additions & 5 deletions jsonslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,22 +1268,25 @@ func skipObject(input []byte, i int) (int, error) {
unmark := mark + 2 // ] or }
nested := 0
instr := false
prev := mark
i++
for i < l && !(input[i] == unmark && nested == 0 && !instr) {
ch := input[i]
if ch == '"' {
if prev != '\\' {
instr = !instr
if ch == '\\' {
i += 2
if i >= l {
return i, errUnexpectedEnd
}
continue
}
if ch == '"' {
instr = !instr
} else if !instr {
if ch == mark {
nested++
} else if ch == unmark {
nested--
}
}
prev = ch
i++
}
if i == l {
Expand Down
4 changes: 3 additions & 1 deletion jsonslice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ func Test_Fixes(t *testing.T) {
// closing square bracket inside a string value has been mistakenly seen as an array bound
{[]byte(`{"foo":["[]"],"bar":123}`), `$.bar`, []byte(`123`)},
// escaped backslash at the end of string caused parser to miss the end of string
{[]byte(`{"foo":"\\","bar":123}`), `$.bar`, []byte(`123`)},
{[]byte(`{"foo":"foo \\","bar":123}`), `$.foo`, []byte(`"foo \\"`)},
// escaped backslash at the end of string caused parser to miss the end of string
{[]byte(`[{"foo":"foo \\","bar":123}]`), `$[0].foo`, []byte(`"foo \\"`)},
}

for _, tst := range tests {
Expand Down

0 comments on commit 882a55f

Please sign in to comment.