rendrjs/rendr

Array parameters changed from `foo[]=1&foo[]=2` to `foo=1&foo=2`

wvengen opened this issue · 7 comments

After a recent update of master, I find that array parameters are passed through differently (see title). This broke querying with array parameters for my Rails-based API.

I suspect that 33ba314 is the culprit, with url.format using querystring to create the query string, instead of passing through the path as composed by qs (I guess here).

thanks for reporting this! can you give some quick example code of how you were running into this issue? (is it in a controller or?)

I guess this would help - #423

Good news, bad news on this.. i can pretty easily get it to output ?q[0]=1&q[1]=3 but not ?q[]=1&q[]=3 - and i'm pretty sure things like rails doesn't like the index to be there. The reason why it currently outputs ?q=1&q=3 is

qs is setup to be able to parse either option, but i think it only ever outputs with index. Would having the index in the array be a deal breaker for you? I'm having problems finding anything in node that formats it with []'s... but they can all read it with them.

Thanks for looking into this!

I've tested Ruby on Rails 4.1.6 and that doesn't accept arrays indexed with numbers :( And I'm probably not the only one using Rails. I see a couple of options:

  • Fix qs (e.g. when option indices is set to 'empty' output with ?q[]=1&q[]=3)
  • Use querystring like before (though it's been a while since its last update)
  • Use qs2
  • Document how to handle this server-side

It seems this has the attention of upstream :) See ljharb/qs#46 and ljharb/qs#65

thanks for all the info on this! just opened up a PR for it.

Thank you, it works! And I guess after arrayFormat has been implemented, we might be able to use qs again.