-
-
Notifications
You must be signed in to change notification settings - Fork 956
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
support array value in searchParams #1559
Comments
The defaults are intentionally strict to prevent mistakes. However, the {
searchParams: new URLSearchParams(Object.entries({
a: ['b', 'c']
}))
} |
Yeah, I can find some workarounds and solve that problem in my code, but it is not easy
I don't think array is a mistake. Also it works in 9.x and this behaviour can be ported to 11.x in one line |
There are multiple common ways to represent arrays in a query string. Comma is just one of them. It's better to be explicit about it than using implicit stringification behavior. You could also use https://github.com/sindresorhus/query-string and just pass the stringified query parameters to This behavior has been like this for a very long time now and (AFAIK) you're the first one to complain about it, so it doesn't seem like such a big issue. |
sad |
maybe use |
On the other hand no one can forbid user to do |
No. We don't want to have to proxy all those options through Got. It's an edge-case anyway. The default works for most and when it doesn't, there are many ways to get different behavior as I described in my previous comment. |
as I understand documentation, there is only one option
It is not easy in large codebases
What if it is a survival bias? Maybe many users don't create issues and just starting to use other library silently or never updates to new major versions? |
I'll leave this issue open so the other maintainer and users can chime in, but I've shared my opinion about this. |
I agree 100% with @sindresorhus |
A small note on the Got 9 behavior.
|
What problem are you trying to solve?
easier migration from 9.x to 11.x :)
Describe the feature
in 9.x I can pass an array to
query
field and it stringified likearr.join(',')
(default array toString behaviour). examplein 11.x
query
was renamed tosearchParams
and validation was added. Now exception is thrown when I try to pass an array:https://github.com/sindresorhus/got/blob/v11.8.1/source/core/index.ts#L1111
I add
&& !is.array(value)
to thatif
and it seems to work.URLSearchParams supports arrays too, in different ways:
Maybe we can return array to the list of allowed values?
Checklist
The text was updated successfully, but these errors were encountered: