Skip to content

Commit 4cf345e

Browse files
authored
Merge pull request #383 from KimHyeonwoo/master
Fix unexpected behavior when buffer ends with backslash
2 parents a75c1c6 + f83142d commit 4cf345e

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

decode_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,3 +3985,23 @@ func TestIssue372(t *testing.T) {
39853985
t.Errorf("unexpected result: %v != %v", got, expected)
39863986
}
39873987
}
3988+
3989+
type issue384 struct{}
3990+
3991+
func (t *issue384) UnmarshalJSON(b []byte) error {
3992+
return nil
3993+
}
3994+
3995+
func TestIssue384(t *testing.T) {
3996+
testcases := []string{
3997+
`{"data": "` + strings.Repeat("-", 500) + `\""}`,
3998+
`["` + strings.Repeat("-", 508) + `\""]`,
3999+
}
4000+
for _, tc := range testcases {
4001+
dec := json.NewDecoder(strings.NewReader(tc))
4002+
var v issue384
4003+
if err := dec.Decode(&v); err != nil {
4004+
t.Errorf("unexpected error: %v", err)
4005+
}
4006+
}
4007+
}

internal/decoder/stream.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func (s *Stream) skipObject(depth int64) error {
280280
if char(p, cursor) == nul {
281281
s.cursor = cursor
282282
if s.read() {
283-
_, cursor, p = s.statForRetry()
283+
_, cursor, p = s.stat()
284284
continue
285285
}
286286
return errors.ErrUnexpectedEndOfJSON("string of object", cursor)
@@ -343,7 +343,7 @@ func (s *Stream) skipArray(depth int64) error {
343343
if char(p, cursor) == nul {
344344
s.cursor = cursor
345345
if s.read() {
346-
_, cursor, p = s.statForRetry()
346+
_, cursor, p = s.stat()
347347
continue
348348
}
349349
return errors.ErrUnexpectedEndOfJSON("string of object", cursor)
@@ -401,7 +401,7 @@ func (s *Stream) skipValue(depth int64) error {
401401
if char(p, cursor) == nul {
402402
s.cursor = cursor
403403
if s.read() {
404-
_, cursor, p = s.statForRetry()
404+
_, cursor, p = s.stat()
405405
continue
406406
}
407407
return errors.ErrUnexpectedEndOfJSON("value of string", s.totalOffset())

0 commit comments

Comments
 (0)