Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing object with array doesn't split a value #357

Closed
ghost opened this issue Mar 11, 2020 · 5 comments
Closed

Parsing object with array doesn't split a value #357

ghost opened this issue Mar 11, 2020 · 5 comments

Comments

@ghost
Copy link

ghost commented Mar 11, 2020

Parsing a query string object with parameter that intended to be an array doesn't split value by comma, while query string in a form of string is parsed correctly.

This is an issue when integrating with frameworks like HAPI that provides query string as a dictionary.

Example

const qs = require('qs');

// Works
console.log(qs.parse('color=a,b', { comma: true }));
// Result: { color: [ 'a', 'b' ] }

// Doesn't work
console.log(qs.parse({ color: 'a,b' }, { comma: true }))
// Result: { color: 'a,b' }
// Expected result as above: { color: [ 'a', 'b' ] }
@ljharb
Copy link
Owner

ljharb commented Mar 11, 2020

parse is meant to take a string, not an object - when it does take an object, it assumes the parsing (including spitting on commas) to already be done.

@ghost
Copy link
Author

ghost commented Mar 13, 2020

I see. Then the query parsing example on Hapi is incorrect:
https://hapi.dev/api/?v=19.1.1#-serveroptionsqueryparser

@ljharb
Copy link
Owner

ljharb commented Mar 13, 2020

I don't think it is - i think it's that the "comma" option didn't exist when those docs were written.

@ljharb
Copy link
Owner

ljharb commented Mar 15, 2020

After some of the discussion in the hapi issue, I think that it's reasonable that parse with the object form still can split the commas.

@ghost
Copy link
Author

ghost commented Mar 15, 2020

I have prepared a pull request for this: #359

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant