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

WHATWG URL API: base ignored if relative path starts with a double slash #30776

Closed
scottinet opened this issue Dec 3, 2019 · 4 comments
Closed
Labels
invalid Issues and PRs that are invalid. whatwg-url Issues and PRs related to the WHATWG URL implementation.

Comments

@scottinet
Copy link

  • Version: 12.13.1
  • Platform: all
  • Subsystem: url

Instantiating a new WHATWG URL with a base option, and a relative URL starting with a double slash ends up with the base option being ignored.

How to reproduce

const foo = new URL('//foo/bar', 'http://fake');

Expected result

URL {
  href: 'http://fake//foo/bar',
  origin: 'http://fake',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'fake',
  hostname: 'fake',
  port: '',
  pathname: '//foo/bar',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

Actual result

URL {
  href: 'http://foo/bar',
  origin: 'http://foo',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'foo',
  hostname: 'foo',
  port: '',
  pathname: '/bar',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}
@jasnell
Copy link
Member

jasnell commented Dec 3, 2019

Per the URL standard, this appears to be working as expected. That is, the actual result above is correct and you should see similar/identical results both in Chrome and Firefox.

@jasnell jasnell added whatwg-url Issues and PRs related to the WHATWG URL implementation. invalid Issues and PRs that are invalid. labels Dec 3, 2019
@scottinet
Copy link
Author

I see, the protocol can be relative, and the documentation does state that the base is used if the URL is not absolute. Then again, this is a bit of a edge case: I cannot have relative URLs starting with a double-slash with the WHATWG URL API (as dubious as that might be), even though this makes for a perfectly valid relative URL.

@jasnell
Copy link
Member

jasnell commented Dec 3, 2019

It may be worth opening an issue in the url standard repo

@scottinet
Copy link
Author

Yeah, sorry for that issue, I didn't know about the relative protocol thing. 😑
I was trying to reproduce the same behavior as with the legacy URL api with WHATWG but concerning this very particular and not very interesting case, we'll just make our HTTP router stricter.

Thanks for looking into this. 👍

scottinet added a commit to kuzzleio/kuzzle that referenced this issue Dec 6, 2019
# Description

Fix a bug where an URL containing both a trailing slash and a querystring would be incorrectly parsed.

# How to reproduce

The following HTTP GET request works fine:

`http://localhost:7512/_now?pretty`

But not this one without this PR:

`http://localhost:7512/_now/?pretty`

Both requests are equivalent and should be regarded as identical.

# Other changes

~Use the WHATWG URL parsing API instead of the legacy (and deprecated) Node.js URL parser.
Unfortunately, the latter was much more adapted to URL parsing server-side than the former. 😑~

Reverted to the legacy URL API because of:
* nodejs/node#30334 (huge performance hit with WHATWG)
* nodejs/node#30776 (bug with relative URLs starting with double-slashes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Issues and PRs that are invalid. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

No branches or pull requests

2 participants