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

URL: trim leading slashes of file URL paths #278

Merged
merged 1 commit into from
Mar 29, 2017

Conversation

annevk
Copy link
Member

@annevk annevk commented Mar 22, 2017

Tests: web-platform-tests/wpt#5195.

Closes #234 by superseding it. Fixes #232.


Preview | Diff

@annevk
Copy link
Member Author

annevk commented Mar 22, 2017

When I implement this in whatwg-url I'm left with a single failing test and currently unsure as how to fix it:

  1) Web platform tests parsing </..//localhost//pig> against <file://lion/>:

      AssertionError: href
      + expected - actual

      -file:///localhost//pig
      +file://lion/localhost//pig

@annevk
Copy link
Member Author

annevk commented Mar 22, 2017

I think the problem is that https://url.spec.whatwg.org/#file-slash-state doesn't copy the base's host over and we never tested that path before... I guess code coverage isn't everything.

@annevk
Copy link
Member Author

annevk commented Mar 22, 2017

Should be all good now. Also updated the tests PR.

url.bs Outdated
<li><p>If <var>url</var>'s <a for=url>scheme</a> is "<code>file</code>" and <a>c</a> is
<a>EOF code point</a>, "<code>?</code>", or "<code>#</code>", then while <var>url</var>'s
<a for=url>path</a>'s <a for=list>size</a> is not 1 and <var>url</var>'s
<a for=url>path</a>[0] is the empty string, <a>validation error</a>, <a for=list>remove</a>
Copy link
Member

Choose a reason for hiding this comment

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

Path initially can be empty (e.g.: file://) and then path[0] can not be accessed. So I think "is not 1" must be changed to "is greater than 1",

Copy link
Member Author

Choose a reason for hiding this comment

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

Either we don't have coverage or that doesn't cause failure in the JavaScript implementation.

Copy link
Member

Choose a reason for hiding this comment

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

In JavaScript path[0] in such case is undefined, so test path[0] === "" fails. But for example in C++ this can cause exception or runtime error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's what I figured. Should maybe assert for length being 0 to make sure we have coverage.

We should probably also clarify in the Infra Standard that [] indexing only works for actual entries (or make it work like JavaScript somehow, but not sure that's better).

Copy link
Member

Choose a reason for hiding this comment

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

I think just changing "path's size is not 1" to "path's size is greater than 1" solves this problem, because path[0] then will be not accessed.

Copy link
Member Author

Choose a reason for hiding this comment

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

So with file:// I think path will still be non-empty due to 1.4.2. We don't have any testcase that triggers path's size being 0. Maybe we don't test file:// explicitly though.

(That's the reason I wanted to add the assert first. I want to make sure it would actually be triggered. I agree that greater than is what we want here.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I can't trigger it with file://. I'll change to greater than though for clarity.

@annevk annevk requested a review from domenic March 27, 2017 11:40
Also copy file URL hosts correctly for path-absolute input.

Tests: web-platform-tests/wpt#5195.

Closes #234 by superseding it. Fixes #232.
@annevk annevk force-pushed the annevk/file-url-path-slashes branch from b0e1446 to 91bcea4 Compare March 28, 2017 13:08
domenic added a commit to jsdom/whatwg-url that referenced this pull request Mar 29, 2017
@annevk annevk merged commit 6103e0a into master Mar 29, 2017
@annevk annevk deleted the annevk/file-url-path-slashes branch March 29, 2017 10:05
domenic added a commit to jsdom/whatwg-url that referenced this pull request Apr 3, 2017
rmisev added a commit to upa-url/upa that referenced this pull request May 24, 2020
rmisev added a commit to upa-url/upa that referenced this pull request May 24, 2020
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.

3 participants