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

Object with "number" keys are stringyfied as arrays #411

Open
richarddd opened this issue Apr 22, 2021 · 3 comments
Open

Object with "number" keys are stringyfied as arrays #411

richarddd opened this issue Apr 22, 2021 · 3 comments

Comments

@richarddd
Copy link

richarddd commented Apr 22, 2021

If i run this code i would expect the resulting object to be {params: {"2": "1"}}

qs.parse(qs.stringify({params: {"2": 1}}))

Qs parses it as:
{params: ["1"]}

@ljharb
Copy link
Owner

ljharb commented Apr 23, 2021

Since qs.stringify({params: {"2": 1}}, { encodeValuesOnly: true }) produces 'params[2]=1', this seems like an issue with parse.

However, while qs.parse('params[2]=1') produces { params: [ '1' ] }, qs.parse('params[2]=1', { allowSparse: true }) produces { params: [ <2 empty items>, '1' ] }, so i think the thing you're looking for is the allowSparse option?

@dessskris
Copy link

Hi, we are having the same issue, however we only observe it on numbers up to 20.

So for example, this will work correctly:

{params: {"21": "1"}}

but not this:

{params: {"20": "1"}}

I don't have the allowSparse option (FYI we are using qs version 6.7.0)

Any ideas? Thanks.

@ljharb
Copy link
Owner

ljharb commented Apr 27, 2021

@dessskris thats because the arrayLimit option defaults to 20.

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

3 participants