Skip to content

Commit

Permalink
fix(dec.arr): handle whitespace after comma
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Nov 2, 2021
1 parent 0d696ce commit 1571e57
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dec_arr.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func (d *Decoder) Arr(f func(d *Decoder) error) error {
return xerrors.Errorf("next: %w", err)
}
for c == ',' {
// Skip whitespace before reading element.
if c, err = d.next(); err != nil {
return xerrors.Errorf("next: %w", err)
}
d.unread()
if err := f(d); err != nil {
return xerrors.Errorf("callback: %w", err)
}
Expand Down
7 changes: 7 additions & 0 deletions dec_arr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ func TestDecoder_Arr(t *testing.T) {
require.Error(t, d.Arr(nil))
}
})
t.Run("Whitespace", func(t *testing.T) {
d := DecodeStr(`[1 , 2, 3 ,45, 6]`)
require.NoError(t, d.Arr(func(d *Decoder) error {
_, err := d.Int()
return err
}))
})
t.Run("Depth", func(t *testing.T) {
var data []byte
for i := 0; i <= maxDepth; i++ {
Expand Down

0 comments on commit 1571e57

Please sign in to comment.