43081j / picoquery

A small library for parsing and serializing query strings
MIT License
74 stars 2 forks source link

fix: nested repeated array syntax (#43) #44

Closed 43081j closed 5 months ago

43081j commented 5 months ago

Fixes #42

Essentially we had two bugs :eyes:

Bug 1: if you have repeat syntax when using bracket-notation, but only had one key, we would not create it as a string.

For example:

parse('foo[]=1', opts); // {foo: 1} - wrong!

parse('foo[]=1&foo[]=2', opts); // {foo: [1, 2]} - right!

Bug 2: if you have repeat syntax following an index-nested member, we would not parse it correctly.

For example:

parse('foo[bar][]=1', opts); // {foo: {bar: 1}} - wrong!

// expected: {foo: {bar: [1]}}

These should both now be fixed.