-
Notifications
You must be signed in to change notification settings - Fork 13
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
Multi-valued query parameter only picks up the last value #29
Comments
Interesting. Out of curiousity, what is the use-case for this? Why not use I'm open to this functionality but I think returning a string or a vector, depending on input, is a misfeature as it will complicate all user code. Perhaps there could be a setting to always return vectors. |
Browsers send it like this, when a form has multiple inputs with the same name, so the meta - use-case are all progressively-enhanced web-apps. Admittedly, due to ring's design, we are in somewhat of a pickle here. Even pedestal seems to have copied it. And a lot of web devs seem to successfully ignore this corner. I don't think that there is an easy way out, at this point. Maybe the best way would be to have an option to expect a multi-valued parameter and to raise a condition for unexpectedly multi-valued parameters. |
Browsers have built-in escaping (by percent-encoding) so that we don't have to reinvent it. Amongst the thousands of implementations of your suggestion, that are bound to exist in the wild, how many do you think will correctly handle a parameter map of |
FWIW cljs-ajax has a concept of The default is similar behaviour to the browser, and called
There is also a
(I find the names a bit odd.) Perhaps silk could have a vec-strategy too, e.g.
I think, the big question is: which do you choose as the default? Alternatively, silk could adopt so-called
Of course, both could be combined and the |
Good find! How about allowing the parser to distinguish parameters, that are expected to be multi-valued? Something like: > (domkm.silk/decode-query "foo=Greg&bar=Linda&foo=John&moo=Mary" :multi #{"foo" "moo"})
{"foo" ["Greg" "John"],
"bar" "Linda"
"moo" ["Mary"]} I don't think we should attempt to support any of the conventions as part of this ticket. This is about a fundamental restriction. If it's lifted, you can do any strategy that you like, on top of it. |
I've pushed an implementation of the idea from my last comment bendlas@bfd371c I could make a PR out of this, if people like this idea |
Thanks @bendlas. I'm open to a PR for this. Could you add tests and documentation? |
Sure, I'll have to do another pass, because two tests are failing. I'll get back. |
Such query-strings are allowed and widely supported [1] [2]. Even ring has some (admittedly dodgy) support for this, where it would return a vector, when there are multiple values to a query key.
[1] https://developer.mozilla.org/en/docs/Web/API/URLSearchParams/getAll
[2] https://google.github.io/closure-library/api/goog.Uri.QueryData.html#getValues
The text was updated successfully, but these errors were encountered: