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

Multiple query parameters with same key aren't handled properly #1146

Closed
bradvogel opened this issue Dec 26, 2014 · 7 comments
Closed

Multiple query parameters with same key aren't handled properly #1146

bradvogel opened this issue Dec 26, 2014 · 7 comments

Comments

@bradvogel
Copy link

Specify this route in your code:

Router.route('/testroute', function() {
  console.log(this.params.query)
}, {
  where: 'server'
});

Now load: localhost:3000/testroute?param=1&param=2

Expected result in console:

{
   "param": ["1", "2"]
}

Actual result in console:

{
   "param": "2"
}
@dburles
Copy link
Contributor

dburles commented Jan 1, 2015

Hey @bradvogel this is expected behavior, you need to pass the query params like param[]=1&param[]=2 for them to be treated as an array

@bradvogel
Copy link
Author

That isn't how the browser works though. The following form:

    <form action="/" method="get">
        <input name="param">
        <input name="param">
        <input type="submit">
    </form>

will submit to the url: /?param=one&param=two

@dburles
Copy link
Contributor

dburles commented Jan 1, 2015

Just rename the field names to param[]. IR will then know to treat them as an array. Not sure if there's any documentation on that now I think about it.

@bradvogel
Copy link
Author

Yes, I see that's a workaround, but this is still a bug. The router should support arbitrarily named multiple parameters, as the spec allows.

@dburles
Copy link
Contributor

dburles commented Jan 1, 2015

I wouldn't say it's a bug. The router/whatever can choose to handle them however they wish and the convention of automatically coercing field names with square brackets into arrays is quite common and it makes handling things much less complicated. I know that Rails (edit: not sure about Django) and PHP do the same thing.

@dburles
Copy link
Contributor

dburles commented Jan 1, 2015

Here's the issue @tmeasday opened with some reasoning behind the choice iron-meteor/iron-url#1

@bradvogel
Copy link
Author

Ok, thanks for the help. I filed iron-meteor/iron-url#8 as a feature request. Closing this. Thanks!

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

No branches or pull requests

2 participants