-
-
Notifications
You must be signed in to change notification settings - Fork 737
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
Inconsistent behaviour of "arrayLimit" #294
Comments
If there's no brackets, it's not necessarily an array - the server is free to treat it as "last one wins", "first one wins", or "an array". If it's important it be an array, you should always use the brackets. I'm not sure what the request is here - the parameter name is what it is. Are you suggesting a rename? |
By default I created the issue because I could not understand why my two Regarding the option name ( |
Ah, thanks for clarifying. The reason it’s needed is because you can do |
With |
Would you want to submit a PR improving the docs to make it more clear why the option is needed? |
@ljharb I've submitted the PR. I intentionally specified that the problem is only with iteration over the array (and this iteration happens in |
I mean, the same issue would occur with anyone iterating over the array with a method that didn’t skip holes, so it’s not just internal to qs. |
From documentation:
var noSparse = qs.parse('a[1]=b&a[15]=c');
assert.deepEqual(noSparse, { a: ['b', 'c'] }); It says that |
ah, fair enough. |
Honestly I think |
we’d add a dependency on the object.values or object.entries package in that case; or use a for..in loop. |
From readme:
Value
20
is configurable byarrayLimit
option.First of all,
arrayLimit
as a name for the option is very confusing. I would expect that resulting array will contain no more thanarrayLimit
items and the rest items will be rejected. However, this is not correct. All values will be parsed but instead of an array I will get an object.Ok, but what's the problem with
arrayLimit
. Actually it works only with array defined using bracket form:If I have more than 21
ids
in a query string, the resulting value will be parsed as an object:However, if array is defined without brackets,
arrayLimit
will not be honoured:If I have for example 30
ids
in a query string, the resulting value will be parsed as an array:The text was updated successfully, but these errors were encountered: