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

stringify: Arrays | implicit and explicit indexing, empty fields #77

Open
buschtoens opened this issue Sep 9, 2013 · 2 comments
Open
Labels

Comments

@buschtoens
Copy link
Collaborator

var arr = [0, 1, 2, 3, 4];
delete arr[3];

console.log(qs.stringify({ a: arr, b: undefined }));
// => a[0]=0&a[1]=1&a[2]=2&a[3]=undefined&a[4]=4&b=
@buschtoens
Copy link
Collaborator Author

Empty array fields should be preserved to keep the indexing, but should be empty, just like b.

a[0]=0&a[1]=1&a[2]=2&a[3]=&a[4]=4&b=

Maybe, we could also completely drop the empty field, when using explicit indexing.

a[0]=0&a[1]=1&a[2]=2&a[4]=4&b=

However, when the last element of the index is undefined/null this would change the array length. Although this is an edge case, it can break certain apps.

Tomorrow I'll do some tests, to see how different browsers handle a mix of implicit and explicit indexing, so we can optimize the output length.

@tj
Copy link
Owner

tj commented Sep 9, 2013

the reason we can't allow holes is because you could do foo[0]=bar&foo[999999999]=baz

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

No branches or pull requests

2 participants