At one point in history, server side languages started tweaking urlencoded parameters to add support for submitting data as arrays and key/value objects:
// key/value pairs
contact[name]=John
contact[phone]=800-555-1234
// arrays
foo[]=bar
foo[]=baz
I’m playing around with some edge cases in one library's nested parameter parsing, eg preservation of parameter order. Is there a spec that formalizes how a server should process this encoding? If not, which reference implementation introduced this syntax?
Square brackets in URIs
According to RFC-3986 "Uniform Resource Identifier (URI): Generic Syntax" using unencoded square brackets in URIs isn't allowed. Therefore it's not a HTTP standard.
A host identified by an Internet Protocol literal address, version 6 [RFC3513] or later, is distinguished by enclosing the IP literal within square brackets ("[" and "]"). This is the only place where square bracket characters are allowed in the URI syntax.
Many programming languages are using square brackets for arrays, therefore I guess it was a natural carry-over to use square brackets in URIs.
Is there a spec that formalizes how a server should process this encoding?
No, at least not language independent.
First Implementation
A lot of web application frameworks allow reuse of the same key in the query to create an array, for example http://example.org/?foobar=hello&foobar=world
. These frameworks also allow to use square brackets in keys, but it makes no difference, they are just part of the name. Associative arrays are rarely supported. (Caveat: I'm not familiar with all this languages.)
So far PHP is the only language I've found, which supports associative arrays in URLs without custom code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With