W3C home > Mailing lists > Public > whatwg@whatwg.org > March 2009

[whatwg] URL decomposition on HTMLAnchorElement interface

From: Biju <bijumaillist@gmail.com>
Date: Thu, 26 Mar 2009 23:01:34 -0400
Message-ID: <4a27dd80903262001y32d94941vc58d1be1e36474f3@mail.gmail.com>
On Thu, Mar 26, 2009 at 5:26 PM, Kartikaya Gupta
> This behavior seems rather inconsistent and possibly buggy.

At first look I also thought it is inconsistent
But later I found Firefox is very consistent.
I think reason why it happening like that is because Firefox clean up
URL by removing extra slash before host name
and adding a slash after host name and also convert host name to lowercase.

Try this

var a = document.createElement('a');
a.setAttribute('href', 'http:/Example.org:123/foo?bar#baz');   //Case 1
alert(a.href);
a.setAttribute('href', 'http:example.org:123/foo?bar#baz');    //Case 2
alert(a.href);
a.setAttribute('href', 'http:///example.org:123/foo?bar#baz');    //Case 3
alert(a.href);
a.setAttribute('href', 'http://///example.org:123/foo?bar#baz');    //Case 4
alert(a.href);

Firefox clean up the URL
and all shows "http://example.org:123/foo?bar#baz"

So now when you set host as null, I ASSUME following is happening

"http://example.org:123/foo?bar#baz"
===>
"http://<<<blank>>>/foo?bar#baz"
===>
"http:///foo?bar#baz"
===>
"http://foo/?bar#baz"


Firefox do this same for protocols http, https, ftp for others it wont
allow hostname change.

Setting
a.hash = null;
a.search = null;
are allowed for http, https, ftp, file and jar
(may be for data: also, I have not tested it)

You can use a null string instead of null.
And I know host name can not be set to space or a string containing space.
But it is allowing invalid characters like !$%^&*( etc.
Get confused when it find @#? as hostname

Now question is do we need to allow to set host to a null or ""?

PS: Jar protocol example
"jar:http://example.org:123/foo!/?bar#baz"
Received on Thursday, 26 March 2009 20:01:34 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 30 January 2013 18:47:49 GMT