Skip to content

Commit

Permalink
Fix mapDecoder.DecodeStream() to accept empty objects containing whit…
Browse files Browse the repository at this point in the history
…espace (#425)
  • Loading branch information
abrander authored Mar 13, 2023
1 parent f32a307 commit 7be58ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/decoder/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7be58ac

Please sign in to comment.