Entities have no special meaning in URLs.
> AWSAccessKeyId=1RZJ66V99R267YCDQSG2&Expires=1330162525&Signature=F
> %2FbNMruOog2ejsspsaZTBKVkIHM%3D
> The output of parseQueryString would be this:
> Object { AWSAccessKeyId="1RZJ66V99R267YCDQSG2", amp=[2],
> Expires="1330162525" ... }
> where you can see amp=[2]
`amp` has no value (it is passed twice with just the name). I agree
that there's something weird about the [2] (which looks like [true +
true], haven't looked at the code). Having it be set to null or
undefined makes more sense, so you can find it on the object but with
no value. What are you expecting?
-- Sandy
Since you can't have that, I ask again... what do you think is more correct than returning [2], which I agree is a bug?
-- S.
In that case, it should return
{
'AWSAccessKeyId': '1RZJ66V99R267YCDQSG2',
'amp;Expires': '1330162525',
'amp;Signature': 'F/bNMruOog2ejsspsaZTBKVkIHM='
}
You're using HTML entities in URL-encoded strings, if you don't want
the HTML entities in there, decode the HTML entities first. It is in
no way correct for parseQueryString to automagically decide to do more
than interpret the string as a query string. Feel free to make your
own function called `parseHTMLEntityEncodedQueryString` if you need
that.
--
Tim Wienk, Software Developer, MooTools Developer
E. timw...@gmail.com | W. http://tim.wienk.name
-- S.
{
'AWSAccessKeyId': '1RZJ66V99R267YCDQSG2',
'amp': ['', ''],
'Expires': '1330162525',
'Signature': 'F/bNMruOog2ejsspsaZTBKVkIHM='
}
(which is what it is now, judging from the "[2]"?)
Or there should be a way to specify the query item separator instead.
I guess one could argue that splitting on two different query item
separators in one string is, at least, weird.
I guess the fact that it does, though, has as added benefit that none
of the actual intended keys get messed up by having HTML entity
encoded ampersands in the query string. So changing it to using only
one separator may cause backward compatibility issues.
Sounds like we're in for some fun. :-)
To handle keys that are specified multiple times in a better way (and
the parsing of query strings in general) we could think about
implementing something like Django's QueryDict class.
https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.QueryDict
> (which is what it is now, judging from the "[2]"?)
I presumed that now it's interpreting each name-no-value as if it were
a boolean true, then [true + true] = 2. Obviously that would please
few. :)
-- S.
I wouldn't say it's standard to have duplicate keys turned into an
array *without* an array hint like []. Maybe some CGIs do it, but
others ignore duplicates and keep the first, ignore duplicates and
keep the last, or create a comma-delimited string. It really isn't
standard in any way I would feel safe generalizing to "the average"
back end, let alone userland code that can change, say, the JSP way to
the PHP way.
Any parsing of what is still "officially" an opaque string should
preserve as much data as possible unless the user provides a hint
saying "just give me what this kind of back end is expected to parse".
This would mean that without the hint, the returned object has to be
quite complex and precise. Probably have to return a deeper object
that always has arrays so the user doesn't have to keep typechecking.
{
string_value : ['hello']
, other_string_value : ['gbye1','gbye2']
, boolean_value : [undefined,undefined]
}
-- S.
ASP, ASP.NET, CF do not do this and are definitely in-the-wild.
There's no standard.
-- S.
> https://www.google.com/?foo=1&foo=2&bar=1&bar=2
> This isn't a backend doing the encoding; this is your browser sending a GET
> request. This is how things *normally* work.
Did I question this somewhere? I don't think so...
The question is whether a client-side QS parser should have one, two,
three, or perhaps zero `hints` available as to how it builds its
returned object. You said it's standard for CGIs other than PHP to
parse `foo` into an array. That is simply not true. There are three
major approaches (discard, explode, concatenate) and more servers
in-the-wild running CGIs that *don't* explode the above into an array
than CGIs that do.
-- S.
I agree, there shouldn't be any favoritism toward PHP-explode (though
editorially, I do find it the most self-documenting). There has to be
an object representation that preserves as much info as possible,
including the order of any duplicates, so that it can be transformed
into any other format.
-- S.