miuri.js icon indicating copy to clipboard operation
miuri.js copied to clipboard

Incorrect parsing of query strings

Open papercreatures opened this issue 12 years ago • 7 comments

it is perfectly valid to have ?a=1&a=2 unfortunately as it uses a dictionary internally, these get squashed. i'll try and patch next week.

papercreatures avatar Feb 22 '13 17:02 papercreatures

So what value should be under a key? In PHP $_GET['a'] will return 2 (Miuri also returns 2). I believe it's valid behavior.

radmen avatar Feb 22 '13 18:02 radmen

PHP is broken then, but we all knew that.

On Friday, 22 February 2013, Radosław Mejer wrote:

So what value should be under a key? In PHP $_GET['a'] will return 2(Miuri also returns 2). I believe it's valid behavior.

— Reply to this email directly or view it on GitHubhttps://github.com/radmen/miuri.js/issues/4#issuecomment-13962558.

papercreatures avatar Feb 22 '13 19:02 papercreatures

Ok, so what is the correct value then? Can You give something like RFC to show the right way?

radmen avatar Feb 23 '13 00:02 radmen

The correct value would be for miuri to not delete duplicate params when parsing. i.e new Miuri("http://a.com?a=2&a=3') should not become http://a.com?a=2 when toString is called.

I'm not sure how you would make a backward compatible change to the query function in order to make it possible to set multiples though. jQuery uses a name, value dictionary.

papercreatures avatar Feb 23 '13 13:02 papercreatures

I'm not sure how you would make a backward compatible change to the query function in order to make it possible to set multiples though.

Are You talking about arrays passed in GET (something like a[]=2&a[]=3)?

radmen avatar Feb 24 '13 23:02 radmen

Yes, but that's just a hacky workaround PHP does. its perfectly valid to do a=1&a=2 sans square brackets

papercreatures avatar Feb 25 '13 08:02 papercreatures

I searched a little at Google. You're right about passing arrays without brackets (didn't know that..). Yet it's not a common thing. jQuery e.g uses brackets (I've used $.param to check it).

Parsing query string to find arrays without brackets won't be much a problem. Building URI with arrays in query is a little bit tricky, because programmer will have to choose which option (brackets or no brackets) to use.

radmen avatar Feb 25 '13 09:02 radmen