mirror of https://github.com/goccy/go-json.git
Merge pull request #338 from orisano/fix/#337
fix: avoid reading the next character in buffer to nul consideration
This commit is contained in:
commit
58b524e43e
|
@ -3842,3 +3842,14 @@ func TestIssue327(t *testing.T) {
|
|||
t.Fatalf("failed to decode. expected %q but got %q", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssue337(t *testing.T) {
|
||||
in := strings.Repeat(" ", 510) + "{}"
|
||||
var m map[string]string
|
||||
if err := json.NewDecoder(strings.NewReader(in)).Decode(&m); err != nil {
|
||||
t.Fatal("unexpected error:", err)
|
||||
}
|
||||
if len(m) != 0 {
|
||||
t.Fatal("unexpected result", m)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,13 +87,13 @@ func (d *mapDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) erro
|
|||
if mapValue == nil {
|
||||
mapValue = makemap(d.mapType, 0)
|
||||
}
|
||||
if s.buf[s.cursor+1] == '}' {
|
||||
s.cursor++
|
||||
if s.equalChar('}') {
|
||||
*(*unsafe.Pointer)(p) = mapValue
|
||||
s.cursor += 2
|
||||
s.cursor++
|
||||
return nil
|
||||
}
|
||||
for {
|
||||
s.cursor++
|
||||
k := unsafe_New(d.keyType)
|
||||
if err := d.keyDecoder.DecodeStream(s, depth, k); err != nil {
|
||||
return err
|
||||
|
@ -117,6 +117,7 @@ func (d *mapDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) erro
|
|||
if !s.equalChar(',') {
|
||||
return errors.ErrExpected("comma after object value", s.totalOffset())
|
||||
}
|
||||
s.cursor++
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue