mirror of https://github.com/goccy/go-json.git
Fix mapDecoder.DecodeStream() to accept empty objects containing whitespace (#425)
This commit is contained in:
parent
f32a307caf
commit
7be58ac89d
|
@ -282,6 +282,14 @@ func Test_Decoder_DisallowUnknownFields(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_Decoder_EmptyObjectWithSpace(t *testing.T) {
|
||||
dec := json.NewDecoder(strings.NewReader(`{"obj":{ }}`))
|
||||
var v struct {
|
||||
Obj map[string]int `json:"obj"`
|
||||
}
|
||||
assertErr(t, dec.Decode(&v))
|
||||
}
|
||||
|
||||
type unmarshalJSON struct {
|
||||
v int
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ func (d *mapDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) erro
|
|||
mapValue = makemap(d.mapType, 0)
|
||||
}
|
||||
s.cursor++
|
||||
if s.equalChar('}') {
|
||||
if s.skipWhiteSpace() == '}' {
|
||||
*(*unsafe.Pointer)(p) = mapValue
|
||||
s.cursor++
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue