query-string
query-string copied to clipboard
Array with single value is stringified as string when using arrayFormat 'comma'
queryString.stringify({values: ['foo']}, {arrayFormat: 'comma'} )
=> values='foo'
when parsing back with arrayFormat 'comma', the result is {values: 'foo'}
here is a test to reproduce the bug (the test fails):
it("parses array with a single value bug", () => {
const q = queryString.stringify(
{ values: ["foo"] },
{ arrayFormat: "comma" },
);
console.log(q);
const parsed = queryString.parse(q, { arrayFormat: "comma" });
console.log(parsed);
expect(parsed).toEqual({
values: ["foo"],
});
});
The information that values is an array is lost when stringifying. Workaround: use `arrayFormat: "bracket-separator"
This bug makes the "comma" format unusable.
@iyedb looks like a duplicate of this issue