diff --git a/about-uris.html b/about-uris.html index d22912db..8b1de422 100644 --- a/about-uris.html +++ b/about-uris.html @@ -5,8 +5,8 @@
Uniform Resource Identifiers (URI) can be one of two things, a Uniform Resource Locator (URL) or a Uniform Resource Name (URN). You likely deal with URLs most of the time. See RFC 3986 for a proper definition of the terms URI, URL and URN
- +URNs name a resource. They are (supposed to) designate a globally unique, permanent identifier for that resource. @@ -84,7 +84,7 @@
mailto:
URLs will be considered by URI.js to be URNs rather than URLs.
That said, the functional differences will not adversely impact the handling of those URLs.
-
+
RFC 3986 Section 3 visualizes the structure of URIs as follows:
@@ -120,31 +120,31 @@- +Components of an domain filename
- In Javascript the query is often referred to as the search.
+ In Javascript the query is often referred to as the search.
URI.js provides both accessors with the subtle difference of .search() beginning with the ?
-character
and .query() not.
- In Javascript the fragment is often referred to as the hash.
+ In Javascript the fragment is often referred to as the hash.
URI.js provides both accessors with the subtle difference of .hash() beginning with the #
-character
and .fragment() not.
urn:example:animal:ferret:nose?name=ferret#foo \ / \________________________/ \_________/ \ / | | | | scheme path & segment query fragment- +
While RFC 2141 does not define URNs having a query or fragment component, URI.js enables these accessors for convenience.
- +URLs (URIs, whatever) aren't easy. There are a couple of issues that make this simple text representation of a resource a real pain
Because URLs look very simple, most people haven't read the formal specification. As a result, most people get URLs wrong on many different levels. The one thing most everybody screws up is proper encoding/escaping.
http://username:pass:word@example.org/
is such a case. Often times homebrew URL handling misses escaping the less frequently used parts such as the userinfo.
some/path/:foo
is a valid relative path (as URIs don't have to contain scheme and authority). Since homebrew URL handlers usually just look for the first occurence of ":" to delimit the scheme, they'll screw this up as well.
+
is the proper escape-sequence for a space-character within the query string component, while every other component prefers %20
. This is due to the fact that the actual format used within the query string component is not defined in RFC 3986, but in the HTML spec.
There is encoding and strict encoding - and Javascript won't get them right: encodeURIComponent()
- +The hostname component can be one of may things. An IPv4 or IPv6 address, an IDN or Punycode domain name, or a regular domain name. While the format (and meaning) of IPv4 and IPv6 addresses is defined in RFC 3986, the meaning of domain names is not.
-DNS is the base of translating domain names to IP addresses. DNS itself only specifies syntax, not semantics. The missing semantics is what's driving us crazy here.
+DNS is the base of translating domain names to IP addresses. DNS itself only specifies syntax, not semantics. The missing semantics is what's driving us crazy here.
ICANN provides a list of registered Top Level Domains (TLD). There are country code TLDs (ccTLDs, assigned to each country, like ".uk" for United Kindom) and generic TLDs (gTLDs, like ".xxx" for you know what). Also note that a TLD may be non-ASCII .香港
(IDN version of HK, Hong Kong).
IDN TLDs such as .香港
and the fact that any possible new TLD could pop up next month has lead to a lot of URL/Domain verification tools to fail.
To make Things worse, people thought it to be a good idea to introduce Second Level Domains (SLD, ".co.uk" - the commercial namespace of United Kingdom). These SLDs are not up to ICANN to define, they're handled individually by each NIC (Network Information Center, the orgianisation responsible for a specific TLD).
Since there is no central oversight, things got really messy in this particular space. Germany doesn't do SDLs, Australia does. Australia has different SLDs than the United Kingdom (".csiro.au" but no ".csiro.uk"). The individual NICs are not required to publish their arbitrarily chosen SLDs in a defined syntax anywhere.
You can scour each NIC's website to find some hints at their SLDs. You can look them up on Wikipedia and hope they're right. Or you can use PublicSuffix.
Speaking of PublicSuffix, it's time mentioning that browser vendors actually keep a list of known Second Level Domains. They need to know those for security issues. Remember cookies? They can be read and set on a domain level. What do you think would happen if "co.uk" was treated as the domain? amazon.co.uk
would be able to read the cookies of google.co.uk
. PublicSuffix also contains custom SLDs, such as .dyndns.org
. While this makes perfect sense for browser security, it's not what we need for basic URL handling.
TL;DR: It's a mess.
- +PHP (parse_str()) will automatically parse the query string and populate the superglobal $_GET
for you. ?foo=1&foo=2
becomes $_GET = array('foo' => 2);
, while ?foo[]=1&foo[]=2
becomes $_GET = array('foo' => array("1", "2"));
.
Ruby's CGI.parse()
turns ?a=1&a=2
into {"a" : ["1", "2"]}
, while Ruby on Rails chose the PHP-way.
Python's parse_qs() doesn't care for []
either.
Most other languages don't follow the []
-style array-notation and deal with this mess differently.
TL;DR: You need to know the target-environment, to know how complex query string data has to be encoded
- +Given the URL http://example.org/index.html#foobar
, browsers only request http://example.org/index.html
, the fragment #foobar
is a client-side thing.