sindresorhus / query-string

Parse and stringify URL query strings
MIT License
6.77k stars 452 forks source link

Regression introduced in 9.1.1: parse cannot read back stringify when using bracket-seperator mode #398

Open dubzzz opened 1 week ago

dubzzz commented 1 week ago

Not sure if it was an expected impact of https://github.com/sindresorhus/query-string/pull/392, but it seems it introduced a regression in 9.1.1.

The following piece of code does not behave the same in 9.1.0 and 9.1.1. In the later the parse function cannot read back itself.

import queryString from 'query-string';

const original = { key: [','] };
console.log({ original });

const stringified = queryString.stringify(original, { arrayFormat: 'bracket-separator' });
console.log({ stringified });

const parsed = queryString.parse(stringified, { arrayFormat: 'bracket-separator' });
console.log({ parsed });

Here are the output we get for each version:

// in 9.1.1
{ original: { key: [ ',' ] } }
{ stringified: 'key[]=%2C' }
{ parsed: [Object: null prototype] { key: [ '', '' ] } }

// in 9.1.0
{ original: { key: [ ',' ] } }
{ stringified: 'key[]=%2C' }
{ parsed: [Object: null prototype] { key: [ ',' ] } }
sindresorhus commented 1 week ago

// @scottenock