jsdom / whatwg-url

An implementation of the WHATWG URL Standard in JavaScript
https://jsdom.github.io/whatwg-url/
MIT License
371 stars 94 forks source link

Inconsistent behavior while parsing the port number #229

Closed igibek closed 2 years ago

igibek commented 2 years ago

Hey, I noticed inconsistent behavior while the port number is parsed in the URL. Specifically, if the port number is equal to 80, whatwg-url will drop it from the returned value. See examples below:

Expected behavior:

new URL("http://admin:secret@google.com:1234/root?foo=bar&boo=baz#anything")
/* returns
{
  scheme: 'http:',
  user: 'admin',
  password: 'secret',
  host: 'google.com',
  port: '1234',
  path: '/root',
  query: '?foo=bar&boo=baz',
  fragment: '#anything'
}
*/

Inconsisted behavior:

new URL("http://admin:secret@google.com:80/root?foo=bar&boo=baz#anything")
/* returns
{
  scheme: 'http:',
  user: 'admin',
  password: 'secret',
  host: 'google.com',
  port: '',
  path: '/root',
  query: '?foo=bar&boo=baz',
  fragment: '#anything'
}
*/
domenic commented 2 years ago

Yep, that's what the spec says to do! https://url.spec.whatwg.org/#ref-for-concept-url-port%E2%91%A2

igibek commented 2 years ago

I missed that part. Thanks for the quick response. However, in general, I think it is non-intuitive behavior from spec :)