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

What should new URL("#") return? #539

Closed
azu opened this issue Sep 2, 2020 · 5 comments
Closed

What should new URL("#") return? #539

azu opened this issue Sep 2, 2020 · 5 comments
Labels
good first issue Ideal for someone new to a WHATWG standard or software project needs tests Moving the issue forward requires someone to write tests

Comments

@azu
Copy link

azu commented Sep 2, 2020

What should be the result of new URL("#")?
Browsers return different results.

In my understanding is that new URL("#") should throw a validation error.

  1. scheme start state
    1. [skip] If c is an ASCII alpha, append c, lowercased, to buffer, and set state to scheme state.
    2. [match] Otherwise, if state override is not given, set state to no scheme state and decrease pointer by 1. → go to no schema state
  2. no schema state
    1. [match] If base is null, or base’s cannot-be-a-base-URL flag is set and c is not U+0023 (#), validation error, return failure. → throw validation error
if ( base === null || (cannot-be-a-base-URL && c !== "#")){
  throw validation error
}

state value

  • base is null (initial value)
  • cannot-be-a-base-URL flag is not set
  • c is #

Test results:

  • Firefox 80.0 → throw TypeError: URL constructor: # is not a valid URL.
  • Chrome 85 → return URL {href: "about:blank#", origin: "null", protocol: "about:", username: "", password: "", …}
  • Safari 13.1.2 → return URL {href: "about:blank#", origin: "null", protocol: "about:", username: "", password: "", …}
  • Node.js 14.5 → throw TypeError [ERR_INVALID_URL]: Invalid URL: #
  • whatwg-url → throw Error

I can not found this test in wpt/url.

📝 Memo:
I've noticed this different result when comparing aTag.href with URL object.
Some <a> element starts with fragment like <a href="#fragment"> and new URL(a.href) got different results.
However, new URL(a.href, location.href) is not problem.

@annevk
Copy link
Member

annevk commented Sep 2, 2020

We should add a test for this. Chrome and Safari are wrong, but they might have matched an earlier version of the standard that mistakenly used about:blank as the default base URL: c2980ee. Although that would not explain new URL("?") throwing and new URL("about:blank?") not throwing, so they are probably just buggy.

@annevk annevk added the needs tests Moving the issue forward requires someone to write tests label Sep 2, 2020
@azu
Copy link
Author

azu commented Sep 2, 2020

Thanks to confirm!

@annevk annevk added the good first issue Ideal for someone new to a WHATWG standard or software project label Sep 7, 2020
@annevk
Copy link
Member

annevk commented Sep 7, 2020

To close this issue two things will need to be done that are relatively straightforward:

  1. New tests will need to be contributed to web-platform-tests (see README) for parsing # without base URL.
  2. Bugs will need to be filed against Chrome and Safari (see https://github.com/whatwg/meta/blob/master/MAINTAINERS.md#handling-pull-requests for where exactly) for getting not throwing a TypeError as expected.

@achristensen07
Copy link
Collaborator

https://bugs.webkit.org/show_bug.cgi?id=216115

@domenic
Copy link
Member

domenic commented Jul 7, 2021

https://bugs.chromium.org/p/chromium/issues/detail?id=1227126

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jul 18, 2021
…ent tests, a=testonly

Automatic update from web-platform-tests
Test URLs with empty query and fragment

Closes whatwg/url#539.

Closes web-platform-tests/wpt#25829 by superseding it.

Co-authored-by: Daijiro Wachi <[email protected]>
--

wpt-commits: 6315c7757a6675f39262167c8196ce562f2a6778
wpt-pr: 29579
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jul 20, 2021
…ent tests, a=testonly

Automatic update from web-platform-tests
Test URLs with empty query and fragment

Closes whatwg/url#539.

Closes web-platform-tests/wpt#25829 by superseding it.

Co-authored-by: Daijiro Wachi <[email protected]>
--

wpt-commits: 6315c7757a6675f39262167c8196ce562f2a6778
wpt-pr: 29579
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Jul 20, 2021
…ent tests, a=testonly

Automatic update from web-platform-tests
Test URLs with empty query and fragment

Closes whatwg/url#539.

Closes web-platform-tests/wpt#25829 by superseding it.

Co-authored-by: Daijiro Wachi <[email protected]>
--

wpt-commits: 6315c7757a6675f39262167c8196ce562f2a6778
wpt-pr: 29579
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Jul 21, 2021
…ent tests, a=testonly

Automatic update from web-platform-tests
Test URLs with empty query and fragment

Closes whatwg/url#539.

Closes web-platform-tests/wpt#25829 by superseding it.

Co-authored-by: Daijiro Wachi <[email protected]>
--

wpt-commits: 6315c7757a6675f39262167c8196ce562f2a6778
wpt-pr: 29579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Ideal for someone new to a WHATWG standard or software project needs tests Moving the issue forward requires someone to write tests
Development

No branches or pull requests

4 participants