A query strings like "x=1&x=2&x=3" should be decoded into list of strings: ["x": ["1", "2", "3"]]
Now Uri.decodeQuery returns only last match ["x": "3"], and has a inappropriate signature too (it returns Str:Str). It's ok and even more useful in cases when you don't deal with lists, but doesn't handle a situation when you need them.
brianFri 29 Oct 2010
Both Uri and the web APIs all work with Str:Str only. True some of the RFCs say you can do this. But in the real world it is not well supported, extremely rarely used, and probably a really bad idea to use it. So I kept the APIs simple and easy to use at the expense of handling odd conditions like this.
brianFri 29 Oct 2010
Actually going back and looking at WebUtil, what I did for HTTP headers was to append them together using the comma. That is probably what Uri.query should do too, I will take a look.
tonskyFri 29 Oct 2010
That's ok, but there's no other way to handle these situations, at all. Let's took this form for example:
Whom to notify?
[ ] brian
[v] andy
[v] tonsky
[submit]
If the list of persons is dynamic, you'll need to create a list of checkboxes with the single name and different values:
Are forms of such kind rare? Or do you have an another way to handle them?
tonskyFri 29 Oct 2010
For example, Django has two different methods to extract param values: one for extracting parameter's single (first) value and another to extract list when you expect it. I think, it's a good compromise between API usefulness and completeness.
brianFri 29 Oct 2010
Renamed from Uri.decodeQuery does not understand list of values with same name to Uri.decodeQuery does not handle duplicate keys
That seems like a good solution for the existing API. Plus the queryStr is still maintained to pass to other APIs or to create a new API if we decide we really need to parse into a Str of Str[].
jodastephenFri 29 Oct 2010
All the query string APIs I know support a Str:Str[] concept (where the Str[] is normally size 1). I'm OK with comma separation as a default for Str:Str, but do believe that the Str:Str[] form is needed on occasion.
katoxFri 29 Oct 2010
but do believe that the Str:Str[] form is needed on occasion.
for &x=a%2Cb&x=y -> &x=a,b&x=y -> a,b,c it is definitely better than extra escaping to preserve the original meaning
tonsky Fri 29 Oct 2010
A query strings like
"x=1&x=2&x=3"
should be decoded into list of strings:["x": ["1", "2", "3"]]
Now
Uri.decodeQuery
returns only last match["x": "3"]
, and has a inappropriate signature too (it returnsStr:Str
). It's ok and even more useful in cases when you don't deal with lists, but doesn't handle a situation when you need them.brian Fri 29 Oct 2010
Both Uri and the web APIs all work with Str:Str only. True some of the RFCs say you can do this. But in the real world it is not well supported, extremely rarely used, and probably a really bad idea to use it. So I kept the APIs simple and easy to use at the expense of handling odd conditions like this.
brian Fri 29 Oct 2010
Actually going back and looking at WebUtil, what I did for HTTP headers was to append them together using the comma. That is probably what Uri.query should do too, I will take a look.
tonsky Fri 29 Oct 2010
That's ok, but there's no other way to handle these situations, at all. Let's took this form for example:
If the list of persons is dynamic, you'll need to create a list of checkboxes with the single name and different values:
Are forms of such kind rare? Or do you have an another way to handle them?
tonsky Fri 29 Oct 2010
For example, Django has two different methods to extract param values: one for extracting parameter's single (first) value and another to extract list when you expect it. I think, it's a good compromise between API usefulness and completeness.
brian Fri 29 Oct 2010
Renamed from Uri.decodeQuery does not understand list of values with same name to Uri.decodeQuery does not handle duplicate keys
brian Fri 29 Oct 2010
Promoted to ticket #1276 and assigned to brian
brian Fri 29 Oct 2010
Ticket resolved in 1.0.56
I pushed a fix - changeset.
If duplicate keys are detected it concats the values using comma:
That seems like a good solution for the existing API. Plus the queryStr is still maintained to pass to other APIs or to create a new API if we decide we really need to parse into a Str of Str[].
jodastephen Fri 29 Oct 2010
All the query string APIs I know support a Str:Str[] concept (where the Str[] is normally size 1). I'm OK with comma separation as a default for Str:Str, but do believe that the Str:Str[] form is needed on occasion.
katox Fri 29 Oct 2010
for
&x=a%2Cb&x=y
->&x=a,b&x=y
->a,b,c
it is definitely better than extra escaping to preserve the original meaningEdit: better formulation
tonsky Mon 1 Nov 2010
thx brian!