This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
The spec says that url.port = '' should remove the port but this does not match browsers: Gecko: Keeps the current port Presto: Keeps the current port WebKit: Sets the port to 0 Blink: Sets the port to 0 IE: Sets the port to 0
Also, location.port is also not consistent. location.port = '' Gecko: Throws Presto: Noop Trident: Sets port to 0 and navigates to it. Actually loads port 80 Blink: Removes the port and navigates WebKit: Removes the port and navigates location.port = 0 Gecko: Throws Presto: Noop Trident: Sets port to 0 and navigates to it. Actually loads port 80 Blink: Sets port to 0 and navigates. Navigation fails of port 0 WebKit: Noop
So normally empty string means the same as the default port: http://test:/ -> http://test/ but it seems that the port setter needs a special case. I prefer the Blink behavior for the special case as it is consistent across objects. (Assuming it would actually succeed loading if I have something hosted on port 0.)
https://github.com/whatwg/url/commit/53dae545e386f26208b8038de55a918ffe421ac8
So bz pointed out that what everyone does here is not very useful and that having "" string mean the default port (ie removing the port) is more useful. Reading comment 1 again it seems that is what Blink/WebKit do for location.port today. So maybe the specification was not that bad here.
> Assuming it would actually succeed loading if I have something hosted on port 0 It wouldn't, since 0 is not a valid port number for any of the protocols we care about.
In https://bugzilla.mozilla.org/show_bug.cgi?id=930450 Gecko decided that the empty string should not be special cased (it will result in .port === ""). To match that I should remove step 2 in the setting algorithm here: http://url.spec.whatwg.org/#dom-url-port
https://github.com/whatwg/url/commit/def2ff3b3881fa9f4cf8ee2b6d622a9c5209c0c3