Skip to content

Prevent the pathname setter from erasing the path of path-only URLs, …#582

Merged
annevk merged 2 commits intowhatwg:mainfrom
karwa:master
Jun 17, 2021
Merged

Prevent the pathname setter from erasing the path of path-only URLs, …#582
annevk merged 2 commits intowhatwg:mainfrom
karwa:master

Conversation

@karwa
Copy link
Copy Markdown
Contributor

@karwa karwa commented Feb 21, 2021

…as that would make them cannot-be-a-base URLs.

Fixes #581

JSDom patch: jsdom/whatwg-url#178

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

…as that would make them cannot-be-a-base URLs.
Copy link
Copy Markdown
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting this, this does look like a somewhat serious oversight.

Comment thread url.bs Outdated

<li><p>Otherwise, if <var>state override</var> is given and <var>url</var>'s
<a for=url>host</a> is null, <a for=list>append</a> the empty string to <var>url</var>'s
<a for=url>path</a>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only when host is null? It seems this needs to generally happen.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because non-special URLs with a host (e.g. foo://somehost) can have an empty string as a path. The issue is limited to path-only URLs.

@annevk annevk requested a review from rmisev February 22, 2021 14:51
@domenic
Copy link
Copy Markdown
Member

domenic commented Feb 23, 2021

Editorially LGTM and matches the tests and jsdom/whatwg-url implementation.

In terms of interop and implementation alignment, of the three tests added in web-platform-tests/wpt#27720:

  • Safari passes test 1 and 3, but not test 2
  • Firefox and Chrome pass test 1, but not test 2 or test 3
  • jsdom/whatwg-url, and thus the current spec, passes tests 1 and 2 but not test 3

Should we consider changing the spec for test 2? I don't have a strong intuition on the model here though so maybe there's a reason that would be bad.

@annevk
Copy link
Copy Markdown
Member

annevk commented Feb 24, 2021

Chrome and Firefox still don't have non-special URLs implemented correctly so I rather not count them.

Safari doesn't seem to allow for removal of the path if there is a host for non-special URLs. I tend to side with OP that it should be possible. That is, if foo://host doesn't create a path and foo://host/ does, it seems nice if you can get from the latter to the former by setting pathname to the empty string.

cc @achristensen07

@karwa
Copy link
Copy Markdown
Contributor Author

karwa commented Feb 24, 2021

I think it is valid (or, well, not disallowed) for some particular schemes/application to treat an empty path differently from a "/" path.

For instance if you're connecting to a remote server: for some hypothetical scheme, myproto://user@host could mean to connect to the user's home directory, and myproto://user@host/ could mean to connect to the remote server's root directory. It may/may not be a good design choice, but if it's allowed, somebody could be relying on it.

Copy link
Copy Markdown
Member

@rmisev rmisev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@annevk
Copy link
Copy Markdown
Member

annevk commented Mar 22, 2021

@achristensen07 any thoughts on this?

@TimothyGu
Copy link
Copy Markdown
Member

It looks like this PR only changes the behavior of test 3 in web-platform-tests/wpt#27720, and Safari already implements the new behavior for test 3. @annevk, would this be enough to count as implementer interest?

@annevk
Copy link
Copy Markdown
Member

annevk commented Jun 14, 2021

I would still prefer to wait for @achristensen07 or someone else from WebKit to weigh in as test 2 does require implementation changes.

@achristensen07
Copy link
Copy Markdown
Collaborator

I haven't gone through the setters like I have the constructor. I think test 2 shows a bug in WebKit that I'm willing to try to change. NSURLComponents already has the behavior that would make test 2 pass, and parsing foo://somehost doesn't add a slash to the path, so I think the path setter shouldn't either, unless called with something that isn't empty and doesn't start with a slash.

@annevk
Copy link
Copy Markdown
Member

annevk commented Jun 16, 2021

Thanks @achristensen07! @karwa can you file a bug against WebKit for that? I don't think we need bugs for Chrome/Firefox as they haven't yet caught up here.

@karwa
Copy link
Copy Markdown
Contributor Author

karwa commented Jun 16, 2021

@annevk annevk merged commit 0672f2e into whatwg:main Jun 17, 2021
@annevk
Copy link
Copy Markdown
Member

annevk commented Jun 17, 2021

I filed nodejs/node#39059 on Node.js.

@annevk
Copy link
Copy Markdown
Member

annevk commented Jun 17, 2021

Thanks @karwa for finding and fixing this! 🎉

annevk added a commit to web-platform-tests/wpt that referenced this pull request Jun 25, 2021
For whatwg/url#582.

Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
domenic pushed a commit to jsdom/whatwg-url that referenced this pull request Jun 25, 2021
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jun 27, 2021
…have their paths erased by th…, a=testonly

Automatic update from web-platform-tests
URL: pathname setter should not erase path-only URL paths

For whatwg/url#582.

Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
--

wpt-commits: 77d54aa9e0405f737987b59331f3584e3e1c26f9
wpt-pr: 27720
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Jul 16, 2021
…have their paths erased by th…, a=testonly

Automatic update from web-platform-tests
URL: pathname setter should not erase path-only URL paths

For whatwg/url#582.

Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
--

wpt-commits: 77d54aa9e0405f737987b59331f3584e3e1c26f9
wpt-pr: 27720
jwidar pushed a commit to jwidar/LatencyZeroGithub that referenced this pull request Sep 16, 2025
…have their paths erased by th…, a=testonly

Automatic update from web-platform-tests
URL: pathname setter should not erase path-only URL paths

For whatwg/url#582.

Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
--

wpt-commits: 77d54aa9e0405f737987b59331f3584e3e1c26f9
wpt-pr: 27720
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Path setter allows cannot-be-a-base URL to be created without the flag

6 participants