forked from mirror/go-json
Merge pull request #383 from KimHyeonwoo/master
Fix unexpected behavior when buffer ends with backslash
This commit is contained in:
commit
4cf345ebdf
|
@ -3985,3 +3985,23 @@ func TestIssue372(t *testing.T) {
|
||||||
t.Errorf("unexpected result: %v != %v", got, expected)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -280,7 +280,7 @@ func (s *Stream) skipObject(depth int64) error {
|
||||||
if char(p, cursor) == nul {
|
if char(p, cursor) == nul {
|
||||||
s.cursor = cursor
|
s.cursor = cursor
|
||||||
if s.read() {
|
if s.read() {
|
||||||
_, cursor, p = s.statForRetry()
|
_, cursor, p = s.stat()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return errors.ErrUnexpectedEndOfJSON("string of object", cursor)
|
return errors.ErrUnexpectedEndOfJSON("string of object", cursor)
|
||||||
|
@ -343,7 +343,7 @@ func (s *Stream) skipArray(depth int64) error {
|
||||||
if char(p, cursor) == nul {
|
if char(p, cursor) == nul {
|
||||||
s.cursor = cursor
|
s.cursor = cursor
|
||||||
if s.read() {
|
if s.read() {
|
||||||
_, cursor, p = s.statForRetry()
|
_, cursor, p = s.stat()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return errors.ErrUnexpectedEndOfJSON("string of object", cursor)
|
return errors.ErrUnexpectedEndOfJSON("string of object", cursor)
|
||||||
|
@ -401,7 +401,7 @@ func (s *Stream) skipValue(depth int64) error {
|
||||||
if char(p, cursor) == nul {
|
if char(p, cursor) == nul {
|
||||||
s.cursor = cursor
|
s.cursor = cursor
|
||||||
if s.read() {
|
if s.read() {
|
||||||
_, cursor, p = s.statForRetry()
|
_, cursor, p = s.stat()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return errors.ErrUnexpectedEndOfJSON("value of string", s.totalOffset())
|
return errors.ErrUnexpectedEndOfJSON("value of string", s.totalOffset())
|
||||||
|
|
Loading…
Reference in New Issue