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 23535 - Should setting port to '' remove the port
Summary: Should setting port to '' remove the port
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: URL (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: Unsorted
Assignee: Anne
QA Contact: sideshowbarker+urlspec
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-16 18:47 UTC by Erik Arvidsson
Modified: 2014-01-08 17:33 UTC (History)
2 users (show)

See Also:


Attachments

Description Erik Arvidsson 2013-10-16 18:47:18 UTC
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
Comment 1 Erik Arvidsson 2013-10-16 19:30:37 UTC
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
Comment 2 Anne 2013-10-24 10:38:13 UTC
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.)
Comment 4 Anne 2013-12-16 14:28:04 UTC
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.
Comment 5 Boris Zbarsky 2013-12-16 14:37:19 UTC
> 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.
Comment 6 Anne 2014-01-07 11:19:57 UTC
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