Skip to content

Setting scheme should set port to null if it matches the default port #327

@broofa

Description

@broofa

When setting port state, https://url.spec.whatwg.org/#port-state says:

  1. Set url’s port to null, if port is url’s scheme’s default port, and to port otherwise

However no corresponding verbiage is included in the process for setting a url scheme. This leads to inconsistent URL states, as illustrated in node.js's current implementation of this standard:

> u1 = new URL('https://foo.com:80')
URL {...}
> u2 = new URL('http://foo.com:443')
URL {...}
> u1.protocol = 'http:'
'http:'
> u2.port = 80
80
> String(u1)
'http://foo.com:80/'
> String(u2)
'http://foo.com/'

u1 and u2 both represent the same URL (scheme, host, port), but u1's port is set to 80, while u2's port is null.

The spec should dictate that when the scheme state is set, the port should be set to null if it matches the default port for that scheme.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs testsMoving the issue forward requires someone to write teststopic: api

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions