millermedeiros / crossroads.js

JavaScript Routes
http://millermedeiros.github.com/crossroads.js/
1.44k stars 156 forks source link

allow multiple query parameters with same name #128

Closed sjhewitt closed 9 years ago

sjhewitt commented 9 years ago

This commit was written by Kamaruni, I'm just submitting it as a pull request to get it merged into master

fixes #90

millermedeiros commented 9 years ago

main problem that I see is that I think there is no standard for multiple parameters with same name.. I've seen ?foo[]=bar&foo[]=baz (PHP does it this way by default) and ?foo=bar&foo=baz and ?foo=bar,baz

sjhewitt commented 9 years ago

I don't see how it's a problem... This solves the problem of getting multivalued parameters from the querystring, not specifying the way the developer should name their parameters. It is a PHP quirk that it requires you to use names that end in [] to specify an array. In the comma separated case, it is the developer that has chosen to encode their values as comma separated, and they should split it themselves.

The simplest case that i'm trying to solve is: given a form like this, that submits using get:

<form method="">
<input type="hidden" name="foo" value="bar">
<input type="hidden" name="foo" value="baz">
<input type="submit">
</form>

Use crossroads to parse the resulting querystring

btw, I've removed the version commit.

millermedeiros commented 9 years ago

@sjhewitt I agree with you, this is good as is. no need to worry about other weird use cases.

sjhewitt commented 9 years ago

Updated with the suggested changes

millermedeiros commented 9 years ago

thanks!

quickstep25 commented 9 years ago

I've been using this pull request version for a few days now. It was much needed and is most appreciated. So far I've had no issues in using it, works perfectly for the app I am using it with.

hendrikstier commented 9 years ago

One question regarding one of the weird use cases with "[]" denoting the array-type of the parameter (here: used with Rails): how can I prevent the parameter name from being URL-encoded?

For example: ...&param%255B%255D=1&... vs ...&param[]=1&