Skip to content

Commit

Permalink
fix(dec.obj): skip whitespace before first field value
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Nov 3, 2021
1 parent 7434d73 commit f9bf819
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dec_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func (d *Decoder) ObjBytes(f func(d *Decoder, key []byte) error) error {
if err := d.consume(':'); err != nil {
return errors.Wrap(err, "field")
}
// Skip whitespace.
if _, err = d.more(); err != nil {
return errors.Wrap(err, "more")
}
d.unread()
if err := f(d, k.buf); err != nil {
return errors.Wrap(err, "callback")
}
Expand Down
2 changes: 1 addition & 1 deletion dec_obj_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestDecoder_ObjectBytes(t *testing.T) {
t.Run("Object", func(t *testing.T) {
i := DecodeStr(`{"id":1,"randomNumber":10}`)
i := DecodeStr(`{ "id" :1 , "randomNumber" : 10 }`)
met := map[string]struct{}{}
require.NoError(t, i.ObjBytes(func(i *Decoder, key []byte) error {
switch string(key) {
Expand Down

0 comments on commit f9bf819

Please sign in to comment.