Description:
When using the arrayFormat: 'comma' option with qs.stringify, an array with a single item is not wrapped as an array when parsed with qs.parse. This behavior leads to inconsistencies, especially when expecting the parsed result to always be an array regardless of the number of items.
Expected Behavior:
When parsing a query string generated with arrayFormat: 'comma', a single item should be wrapped as an array. The expected output should be:
{ fruits: ['apple'] }
Actual Behavior:
The single item is not wrapped as an array:
{ fruits: 'apple' }
Environment:
qs version: ^6.12.1
Steps to Reproduce:
Create an array with a single item.
Use qs.stringify with arrayFormat: 'comma'.
Parse the resulting query string with qs.parse using the same arrayFormat.
Additional Context:
This behavior causes issues when the consistency of data types is important, particularly when handling query strings with arrays that might have a variable number of items.
Description: When using the
arrayFormat: 'comma'
option withqs.stringify
, an array with a single item is not wrapped as an array when parsed withqs.parse
. This behavior leads to inconsistencies, especially when expecting the parsed result to always be an array regardless of the number of items.stackblitz example
Example:
Expected Behavior: When parsing a query string generated with
arrayFormat: 'comma'
, a single item should be wrapped as an array. The expected output should be:Actual Behavior: The single item is not wrapped as an array:
Environment:
qs
version: ^6.12.1Steps to Reproduce:
qs.stringify
witharrayFormat: 'comma'
.qs.parse
using the samearrayFormat
.Additional Context: This behavior causes issues when the consistency of data types is important, particularly when handling query strings with arrays that might have a variable number of items.