From f9bf819530753dcc278799cb4e7fe2d648fcd5ea Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Wed, 3 Nov 2021 22:50:50 +0300 Subject: [PATCH] fix(dec.obj): skip whitespace before first field value --- dec_obj.go | 5 +++++ dec_obj_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dec_obj.go b/dec_obj.go index 3c280e0..e8b6bcc 100644 --- a/dec_obj.go +++ b/dec_obj.go @@ -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") } diff --git a/dec_obj_test.go b/dec_obj_test.go index 93b5f35..7201168 100644 --- a/dec_obj_test.go +++ b/dec_obj_test.go @@ -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) {