diff --git a/decode_test.go b/decode_test.go index c276a324..088367e5 100644 --- a/decode_test.go +++ b/decode_test.go @@ -3985,3 +3985,23 @@ func TestIssue372(t *testing.T) { t.Errorf("unexpected result: %v != %v", got, expected) } } + +type issue384 struct{} + +func (t *issue384) UnmarshalJSON(b []byte) error { + return nil +} + +func TestIssue384(t *testing.T) { + testcases := []string{ + `{"data": "` + strings.Repeat("-", 500) + `\""}`, + `["` + strings.Repeat("-", 508) + `\""]`, + } + for _, tc := range testcases { + dec := json.NewDecoder(strings.NewReader(tc)) + var v issue384 + if err := dec.Decode(&v); err != nil { + t.Errorf("unexpected error: %v", err) + } + } +} diff --git a/internal/decoder/stream.go b/internal/decoder/stream.go index 6f337d77..a383f725 100644 --- a/internal/decoder/stream.go +++ b/internal/decoder/stream.go @@ -280,7 +280,7 @@ func (s *Stream) skipObject(depth int64) error { if char(p, cursor) == nul { s.cursor = cursor if s.read() { - _, cursor, p = s.statForRetry() + _, cursor, p = s.stat() continue } return errors.ErrUnexpectedEndOfJSON("string of object", cursor) @@ -343,7 +343,7 @@ func (s *Stream) skipArray(depth int64) error { if char(p, cursor) == nul { s.cursor = cursor if s.read() { - _, cursor, p = s.statForRetry() + _, cursor, p = s.stat() continue } return errors.ErrUnexpectedEndOfJSON("string of object", cursor) @@ -401,7 +401,7 @@ func (s *Stream) skipValue(depth int64) error { if char(p, cursor) == nul { s.cursor = cursor if s.read() { - _, cursor, p = s.statForRetry() + _, cursor, p = s.stat() continue } return errors.ErrUnexpectedEndOfJSON("value of string", s.totalOffset())