This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 11587 - window.location.hostname should remove brackets of IPv6 host
Summary: window.location.hostname should remove brackets of IPv6 host
Status: RESOLVED WONTFIX
Alias: None
Product: WHATWG
Classification: Unclassified
Component: URL (show other bugs)
Version: unspecified
Hardware: All All
: P4 normal
Target Milestone: Unsorted
Assignee: Anne
QA Contact: sideshowbarker+urlspec
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 20922
  Show dependency treegraph
 
Reported: 2010-12-22 02:08 UTC by NARUSE, Yui
Modified: 2014-10-14 18:12 UTC (History)
9 users (show)

See Also:


Attachments

Description NARUSE, Yui 2010-12-22 02:08:18 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/
Section: http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#dom-uda-hostname

For IPv6 address, URI will be like http://[2001:240:629::6]/foo.html.
On IE and Firefox, when open the URI, window.location.hostname will be "2001:240:629::6".
But Safari 5.0.3 (6533.19.4) and Chrome 10.0.612.3 returns "[2001:240:629::6]".

Mozilla explicitly says remove brackets from hostname.
https://developer.mozilla.org/en/window.location

I think, it is because hostname means DNS name.
So HTML5 spec should describe about this.
Comment 1 Ian 'Hixie' Hickson 2011-01-11 19:59:53 UTC
Agreed that we should at least have an example for this. Not sure what the right behaviour should be though. Removing the brackets leads to an ambiguity as to what should happen when you set the attribute to an IPv6 address (the UA has to recognise it as such and add brackets).

Anyway, I'm going to punt on this pending Adam's URL spec.
Comment 2 Adam Barth 2011-01-12 00:17:32 UTC
This is covered by this test suite:
http://trac.webkit.org/export/LATEST/trunk/LayoutTests/fast/url/segments.html
Comment 3 Michael[tm] Smith 2011-08-04 05:03:34 UTC
mass-moved component to LC1
Comment 4 Anne 2012-09-28 10:48:54 UTC
Why would the brackets be removed? How can you then distinguish it from other host names?
Comment 5 NARUSE, Yui 2012-09-28 15:23:43 UTC
(In reply to comment #4)
> Why would the brackets be removed? How can you then distinguish it from other
> host names?

If it has a colon, it is IPv6 address.
Brackets seem to be required to distinguish from the separator of port, but it won't appear here.
Comment 6 Anne 2012-09-28 15:32:59 UTC
But then scripts that combine the components back together need to first check if the hostname contains a colon so they can add the brackets back. That does not seem ideal.
Comment 7 NARUSE, Yui 2012-09-28 15:38:54 UTC
(In reply to comment #6)
> But then scripts that combine the components back together need to first check
> if the hostname contains a colon so they can add the brackets back. That does
> not seem ideal.

If you want to combine the components, you should use window.location.host,
or just use windows.location.
Such usecase is not intended for this property.
See also https://developer.mozilla.org/en-US/docs/DOM/window.location?redirectlocale=en-US&redirectslug=window.location

I think, it doesn't have brackets because hostname means DNS name.
Comment 8 Anne 2012-09-28 17:20:29 UTC
Well, MDN is nice, but it's not a reference for the standard. It just describes what Gecko does.

As Hixie indicates in comment 1 it also complicates the algorithm for setting because now you have to distinguish IPv6 addresses from everything else in two ways. I do not think what Gecko is doing here makes sense.
Comment 9 NARUSE, Yui 2012-09-29 01:27:34 UTC
Is here thinking ideal behavior of Location object,
or reverse engineering existed implementations/web pages?

The majority of existed web world is IE and Gecko,
and they do the same behavior for setting correct IPv6 address.
So if here is the latter, thinking the behavior makes sense or not is nonsense.


Moreover IPv6 within brackets is URI specific syntax.
In RFC2396 (and RFC 2732) there is "hostname" but its definition is
      hostport      = host [ ":" port ]
      host          = hostname | IPv4address | IPv6reference
      ipv6reference = "[" IPv6address "]"
      hostname      = *( domainlabel "." ) toplabel [ "." ]

RFC 3986 doesn't have "hostname":
      host        = IP-literal / IPv4address / reg-name
      IP-literal = "[" ( IPv6address / IPvFuture  ) "]"

Therefore thinking window.location.hostname is a host defined in RFC3986 doesn't have reason.
Comment 10 Anne 2012-11-24 16:09:24 UTC
I guess we need some tests here for setting and getting hostname. E.g. Gecko does support brackets as input. It seems kinda cumbersome to design a completely separate parser from the normal host parser, but the point that we might need to do this for compatibility is fair.
Comment 11 Anne 2014-01-15 10:59:25 UTC
Okay, so fixing this would be rather easy. When serializing we'd special case IPv6 and when parsing we'd first check for a colon and then prepend input with [ and append ] to it.

However, given that we need to do that special casing it seems what Safari and Chrome are doing is much more sensible.
Comment 12 Anne 2014-10-14 18:12:50 UTC
Gecko was able to change its parser without a hiccup. Seems it still serializes wrong though. Filed a bug on that.

Marking this WONTFIX. Feel free to reopen if this cannot be done for some reason.