Skip to content

Conversation

@rmisev
Copy link
Member

@rmisev rmisev commented Oct 5, 2020

Fixes issue by ensuring file URL's host is not null.

Changes:

  • Set url's host to the empty string at the start of file state.
  • Updates URL parser and serializer accordingly.

Fixes: #549

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


Preview | Diff

This adds the URL is not special condition to the URL serializer's 5.1.
step.

Fixes: whatwg#549

Tests: web-platform-tests/wpt#25989
@annevk
Copy link
Member

annevk commented Oct 6, 2020

This only affects file URLs, right? Not all special URLs. I wonder if we should make that more explicit. There's a couple other cases where the differences between non-file special URLs and file URLs have caused issues, though turning specialness into a tri-state at this point does not seem super attractive either.

@rmisev
Copy link
Member Author

rmisev commented Oct 6, 2020

This only affects file URLs, right? Not all special URLs.

Yes. Non-file special URLs always have not empty host, so they aren't affected. The condition url’s sheme is not "file:" can be used here as well, but 5.1. step is intended for non-special URLs, so I added url is not special. Which one is clearer?

Copy link
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.

That's a good point. Let's do the not special check first though so we start from the most significant component.

@annevk
Copy link
Member

annevk commented Oct 6, 2020

Perhaps @alwinb also wants to review this? And @domenic would ideally verify the tests using whatwg-url.

Writing this I wonder if another fix here could be that file URLs never have a null host. Did you look at that? (That would also allow for removal of step 3 in the serializer and at least one check elsewhere would be simplified so perhaps that's a bigger change best tackled separately.)

@domenic
Copy link
Member

domenic commented Oct 6, 2020

Tested against whatwg-url with web-platform-tests/wpt#25989 and this works. Happy to continue testing other simplifications that folks suggest.

I wonder also if it'd be useful to add a new test suite that uses all of urltestdata.json to test idempotency.

@alwinb
Copy link
Contributor

alwinb commented Oct 6, 2020

Hmm. Resolved file URLs should have a non-null host I think. For a moment I thought that maybe I failed to enforce that in the changes with #405, but I'm not sure now, I guess it was possible before. Anyway, if you can end up with resolved file URLs with a non-null host, I think it's better to change that than to change the serialiser.

The ambiguity can only arise with a null host, and the host being non-null is (or should be) a property of resolved special URLs, so I think the serialiser was correct.

@rmisev rmisev added do not merge yet Pull request must not be merged per rationale in comment topic: parser labels Oct 7, 2020
@annevk
Copy link
Member

annevk commented Oct 7, 2020

Well, the serializer cannot be entirely correct due to step 3 also existing, right? And there's step 2.1.4 of the scheme state which should not have to check for null if that is true. (I think that's all.)

rmisev added 2 commits October 7, 2020 12:02
- Set url's host to the empty string at the start of file state.
- Update URL parser and serializer accordingly
@rmisev
Copy link
Member Author

rmisev commented Oct 7, 2020

Ok, updated URL parser to ensure file url's host is not null.

@rmisev rmisev removed the do not merge yet Pull request must not be merged per rationale in comment label Oct 7, 2020
Copy link
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.

Thank you @rmisev. I like this a lot. I'll wait for @domenic to verify and would appreciate a quick skim from @alwinb as well.

@alwinb
Copy link
Contributor

alwinb commented Oct 7, 2020

@annevk that's true. Step 3 does a bit of resolving inside the serializer, and the check for a null host in 2.1.4 is superfluous if you maintain the invariant that (resolved) file URLs have a non-null host. I don't see any other places either, but I'm not that familiar with this parser so I may have missed something. It seems removing step 3. in the serializer will also solve the idempotency issue, just then you allow null hosts in file URLs.

You could choose to merge this request and make larger changes later, for example together with changes such as for #548. I would try to move any resolving logic out of the serializer, but also prepare for moving it out of the parser. That's another, much larger topic though.

@alwinb
Copy link
Contributor

alwinb commented Oct 7, 2020

Oh I missed the latest changes! I'l have a look in a moment.

@alwinb
Copy link
Contributor

alwinb commented Oct 7, 2020

Yeah looks good.

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

These changes also pass the web platform tests PR and existing suite.

@annevk annevk merged commit a19495e into whatwg:master Oct 8, 2020
@rmisev rmisev deleted the fix-file-reparse branch October 8, 2020 08:44
domenic added a commit to jsdom/whatwg-url that referenced this pull request Oct 8, 2020
domenic added a commit to jsdom/whatwg-url that referenced this pull request Oct 8, 2020
watilde added a commit to watilde/node that referenced this pull request Oct 16, 2020
watilde added a commit to nodejs/node that referenced this pull request Oct 19, 2020
Fixes: #35571
Refs: whatwg/url#550
Refs: web-platform-tests/wpt#25989

PR-URL: #35671
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

File URL reparse issue

4 participants