Skip to content

Commit

Permalink
Merge pull request #383 from KimHyeonwoo/master
Browse files Browse the repository at this point in the history
Fix unexpected behavior when buffer ends with backslash
  • Loading branch information
goccy authored Aug 3, 2022
2 parents a75c1c6 + f83142d commit 4cf345e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 20 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
6 changes: 3 additions & 3 deletions internal/decoder/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 4cf345e

Please sign in to comment.