Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect handling of protocol-relative URLs in 1.5.x #219

Closed
krassowski opened this issue Nov 29, 2021 · 10 comments
Closed

Incorrect handling of protocol-relative URLs in 1.5.x #219

krassowski opened this issue Nov 29, 2021 · 10 comments

Comments

@krassowski
Copy link

krassowski commented Nov 29, 2021

let url = new URL('//github.com');
url.toString()

results in ////github.com but it should result in //github.com.

@offirgolan
Copy link

offirgolan commented Nov 29, 2021

+1 to this:

Screen Shot 2021-11-29 at 3 55 09 PM

FYI - Only seeing this issue in Node but its working correctly in the browser.

@lpinca
Copy link
Member

lpinca commented Nov 30, 2021

Should be fixed on master. See d9e332b. Unfortunately I can't publish a new version.

@offirgolan
Copy link

@lpinca does it make sense for the pathname to be //github.com/foo/bar? Shouldn't it be correctly parsed?

@lpinca
Copy link
Member

lpinca commented Nov 30, 2021

@offirgolan that URL is invalid without a base URL. The WHATWG URL parser throws an error for it. The result is consistent with the legacy Node.js URL parser.

@offirgolan
Copy link

Got it, thanks for the clarification. Do you happen to know how we can get a new release to be published?

@lpinca
Copy link
Member

lpinca commented Nov 30, 2021

Try to ping @3rd-Eden on Twitter (https://twitter.com/3rdEden).

@3rd-Eden
Copy link
Member

Should be fixed on master. See d9e332b. Unfortunately I can't publish a new version.

I need to figure a way to get stuff autopublished.

@3rd-Eden
Copy link
Member

Closing this as I managed to publish this from my windows machine.

Note to self: Using linux commands in publish steps is a bad practice.

@krassowski
Copy link
Author

krassowski commented Dec 28, 2021

Thank you. It still looks a bit weird because new URL('://github.com') is missing hostname, host and has a bit strange pathname when compared to new URL('https://github.com'):

> new URL('//github.com')
{
  slashes: true,
  protocol: '',
  hash: '',
  query: '',
  pathname: '//github.com',
  auth: '',
  host: '',
  port: '',
  hostname: '',
  password: '',
  username: '',
  origin: 'null',
  href: '//github.com'
}

compare to:

> new URL('https://github.com')
{
  slashes: true,
  protocol: 'https:',
  hash: '',
  query: '',
  pathname: '/',
  auth: '',
  host: 'github.com',
  port: '',
  hostname: 'github.com',
  password: '',
  username: '',
  origin: 'https://github.com',
  href: 'https://github.com/'
}

I would have expected that the only differences would be:

  • missing https in href and origin, and
  • empty protocol

but instead there is a difference in pathname, missing hostname, null origin and lack of trailing slash for href.

Is this intended?

@lpinca
Copy link
Member

lpinca commented Dec 28, 2021

@krassowski yes this is expected, see @offirgolan comment above. //github.com is an invalid URL without a base URL. The WHATWG URL parser throws an error without a base URL. This behavior is to be consistent with the legacy Node.js URL parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants