Fix mapDecoder.DecodeStream() to accept empty objects containing whitespace (#425)

This commit is contained in:
Anders Brander 2023-03-13 12:01:01 +01:00 committed by GitHub
parent f32a307caf
commit 7be58ac89d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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
}

View File

@ -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