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

how to handle object keys beginning with a number #38

Closed
Navgeet opened this issue Sep 16, 2014 · 1 comment
Closed

how to handle object keys beginning with a number #38

Navgeet opened this issue Sep 16, 2014 · 1 comment
Assignees
Labels
Milestone

Comments

@Navgeet
Copy link

Navgeet commented Sep 16, 2014

Qs.parse('a%5B12+v%5D=c&a%5Bfoo%5D=bar')
{a: {'12': 'c', foo: 'bar'}}
Qs.parse('a%5B12+v%5D=c');
{a: ['c']}

Is the above behavior expected? If yes, how to handle such keys?

@nlf nlf added the bug label Sep 16, 2014
@nlf nlf self-assigned this Sep 16, 2014
@nlf nlf added this to the 2.2.4 milestone Sep 16, 2014
@nlf
Copy link
Collaborator

nlf commented Sep 16, 2014

Ah, nope not expected. If a key is only a number, it will be parsed as a member of a sparse array. If it only contains a number, it should be getting parsed as an object key, so that's where this bug exists.

Note that you can override the creation of an array at all by passing { arrayLimit: 0 } to the second parameter of Qs.parse

Qs.parse('a%5B12+v%5D=c', { arrayLimit: 0 });
{ a: { '12 v': 'c' } }

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

Successfully merging a pull request may close this issue.

2 participants