From 882a55fa931cb1034965bd34d2366b6b5fb012ae Mon Sep 17 00:00:00 2001 From: Michael Gurov Date: Tue, 24 Dec 2019 17:22:50 +0300 Subject: [PATCH] 1.0.3 --- README.md | 2 ++ jsonslice.go | 13 ++++++++----- jsonslice_test.go | 4 +++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 074e63a..aa03d29 100644 --- a/README.md +++ b/README.md @@ -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 `!~`). diff --git a/jsonslice.go b/jsonslice.go index a482447..b3bdebb 100644 --- a/jsonslice.go +++ b/jsonslice.go @@ -1268,14 +1268,18 @@ 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++ @@ -1283,7 +1287,6 @@ func skipObject(input []byte, i int) (int, error) { nested-- } } - prev = ch i++ } if i == l { diff --git a/jsonslice_test.go b/jsonslice_test.go index 0226f70..9cdd542 100644 --- a/jsonslice_test.go +++ b/jsonslice_test.go @@ -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 {