FIX: Decode back-separator value before splitting it with separator#392
FIX: Decode back-separator value before splitting it with separator#392sindresorhus merged 4 commits intosindresorhus:mainfrom scottenock:fix/decode-bracket-seperator
Conversation
The original implementation was splitting the received value before it then decoded the value. Because the value was URL encoded, the split function could not find the seperator to successfully split. Adjusted the order of operations which fixes #388
|
Thanks for reviewing @sindresorhus 🙌 I've adjusted the test to be more readable with regards to the encoded strings. There's some existing tests that are using encoded values without showing the un-encoded version. Do you want me to adjust these to conform to your comment? |
Yeah, that would be great. |
|
Sweet @sindresorhus, I've updated the tests and they should be more readable. Let me know if there's any issues. |
|
Thanks :) |
|
Not sure if it was an expected change but with 9.1.1 if we run the code below: 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 });We get something different from what we had in 9.1.0. At some point the // 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: [ ',' ] } }I suspect that it might not be totally expected but maybe I'm wrong. |
The original implementation was splitting the received value before it then decoded the value. Because the value was URL encoded, the split function could not find the separator to successfully split. Adjusted the order of operations which fixes #388