[whatwg] URL decomposition on HTMLAnchorElement interface

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 UTC