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

Cleanup API for file and non-special URLs #224

Merged
merged 4 commits into from
Feb 8, 2017

Conversation

annevk
Copy link
Member

@annevk annevk commented Feb 1, 2017

This:

  • Stops the username/password/port APIs from functioning when host is
    the empty string.
  • Makes the host/hostname APIs work better with file URLs and adjusts
    the file host state accordingly.
  • Make setting host/hostname to the empty string impossible when they
    have a username/password/port.
  • Fixes file: URL with a port number through the host setter #97.

This:

* Stops the username/password/port APIs from functioning when host is
the empty string.
* Makes the host/hostname APIs work better with file URLs and adjusts
the file host state accordingly.
* Make setting host/hostname to the empty string impossible when they
have a username/password/port.
* Fixes #97.
annevk added a commit to web-platform-tests/wpt that referenced this pull request Feb 1, 2017
Also file URL host parsing.

See whatwg/url#224 for the corresponding URL Standard change.
@jasnell
Copy link
Collaborator

jasnell commented Feb 1, 2017

This is good but the third bullet (make setting host/hostname to the empty string impossible when they have a username/password/port) seems a bit unnatural to me. What might be better is that setting the host/hostname to the empty string would set the username/password/port to empty strings... but of course, that has side effects that may not be obvious to most users so I'm a bit torn on it.


<ol>
<li><p>If <var>state override</var> is given and <var>url</var>
<a>includes credentials</a>, <a>syntax violation</a>, return.
Copy link
Member

Choose a reason for hiding this comment

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

Is "return" the same as "terminate this algorithm" elsewhere?

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'm slowly switching to Infra terminology.

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 the inconsistency is pretty confusing; when I implemented in whatwg-url I accidentally translated "return" as "bail out of the entire URL parsing algorithm".

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't that what's happening?

Copy link
Member

Choose a reason for hiding this comment

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

No; it's bailing out of this particular state and back into the main parser loop. I.e. it goes back to step 11 ("Keep running the following state machine by switching on state. If after a run pointer points to EOF code point, go to the next step. Otherwise, increase pointer by one and continue with the state machine.")

Copy link
Member

Choose a reason for hiding this comment

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

Err, nevermind, that is what's happening. I guess what I meant is that I translated this as "bail out of this step and go back to step 11". Basically I saw two different types of bail-outs, and since I knew that "abort these steps" meant the one, I assumed that "return" meant the other one. I think it's best to change them all at once or not at all.

@domenic
Copy link
Member

domenic commented Feb 2, 2017

When updating the setters, unfortunately we need to update HTML's location and HTMLHyperlinkElementUtils as well, usually... :-/

@annevk
Copy link
Member Author

annevk commented Feb 2, 2017

@jasnell yeah, it's mostly an edge case I wanted to take care of to avoid messing up serialization. In particular creating a serialization that could not be parsed into the same components.

annevk added a commit to web-platform-tests/wpt that referenced this pull request Feb 2, 2017
Also file URL host parsing.

See whatwg/url#224 for the corresponding URL Standard change.
annevk added a commit to whatwg/html that referenced this pull request Feb 2, 2017
This change depends on whatwg/url#224 landing
first.

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

Location API bits are not tested since we generally treat loading from
file URLs as out-of-scope of the web platform, but accounting for it
standards-wise seemed trivial enough.
@domenic
Copy link
Member

domenic commented Feb 3, 2017

It occurs to me this might be cleaner and require fewer changes in the dependent APIs if you still went to the host/hostname state, but as the first step it just switched to the file host state if the scheme is file and state override is given.

@annevk
Copy link
Member Author

annevk commented Feb 7, 2017

Would you prefer that? I have to say I have very mixed feelings about the whole state override setup.

@domenic
Copy link
Member

domenic commented Feb 7, 2017

I think I would. I found the state override setup confusing at first but now that I understand how it works it seems fine. And given that, preserving the idea that we can just do the API stuff by directly moving into the state override makes sense to me.

@annevk
Copy link
Member Author

annevk commented Feb 8, 2017

Done. I also verified that the tests still pass with whatwg-url.

@domenic
Copy link
Member

domenic commented Feb 8, 2017

LGTM but still would prefer not starting to use "return" without switching over everything all at once.

annevk added a commit to web-platform-tests/wpt that referenced this pull request Feb 8, 2017
Also file URL host parsing.

See whatwg/url#224 for the corresponding URL Standard change.
@annevk annevk merged commit cf616f9 into master Feb 8, 2017
@domenic domenic deleted the annevk/host-hostname-file-urls branch February 8, 2017 18:31
annevk added a commit to whatwg/html that referenced this pull request Feb 8, 2017
This change builds on whatwg/url#224.

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

Location API bits are not tested since we generally treat loading from file URLs as out-of-scope for the web platform, but accounting for it standards-wise seemed trivial enough.
domenic added a commit to jsdom/whatwg-url that referenced this pull request Feb 8, 2017
domenic added a commit to jsdom/whatwg-url that referenced this pull request Feb 8, 2017
TimothyGu added a commit to TimothyGu/node that referenced this pull request Apr 23, 2017
- Update to spec
  - Add opaque hosts
  - File state did not correctly deal with lack of base URL
  - Cleanup API for file and non-special URLs
  - Allow % and IPv6 addresses in non-special URL hosts
  - Use specific names for percent-encode sets
  - Add empty host concept for file and non-special URLs
  - Clarify IPv6 serializer
- Fix existing mistakes
  - Add missing ':' to forbidden host code point list.
  - Correct IPv4 parser empty label behavior
- Maintain type equivalence in URLContext with spec
  - scheme, username, and password should always be strings
  - host, port, query, and fragment may be strings or null
  - Align scheme state more closely with the spec
  - Make sure the `special` variable is always synced with
    URL_FLAG_SPECIAL.

PR-URL: nodejs#12523
Fixes: nodejs#10608
Fixes: nodejs#10634
Refs: whatwg/url#185
Refs: whatwg/url#225
Refs: whatwg/url#224
Refs: whatwg/url#218
Refs: whatwg/url#243
Refs: whatwg/url#260
Refs: whatwg/url#268
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
TimothyGu added a commit to nodejs/node that referenced this pull request Apr 24, 2017
- Update to spec
  - Add opaque hosts
  - File state did not correctly deal with lack of base URL
  - Cleanup API for file and non-special URLs
  - Allow % and IPv6 addresses in non-special URL hosts
  - Use specific names for percent-encode sets
  - Add empty host concept for file and non-special URLs
  - Clarify IPv6 serializer
- Fix existing mistakes
  - Add missing ':' to forbidden host code point list.
  - Correct IPv4 parser empty label behavior
- Maintain type equivalence in URLContext with spec
  - scheme, username, and password should always be strings
  - host, port, query, and fragment may be strings or null
  - Align scheme state more closely with the spec
  - Make sure the `special` variable is always synced with
    URL_FLAG_SPECIAL.

PR-URL: #12523
Fixes: #10608
Fixes: #10634
Refs: whatwg/url#185
Refs: whatwg/url#225
Refs: whatwg/url#224
Refs: whatwg/url#218
Refs: whatwg/url#243
Refs: whatwg/url#260
Refs: whatwg/url#268
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
evanlucas pushed a commit to nodejs/node that referenced this pull request Apr 25, 2017
- Update to spec
  - Add opaque hosts
  - File state did not correctly deal with lack of base URL
  - Cleanup API for file and non-special URLs
  - Allow % and IPv6 addresses in non-special URL hosts
  - Use specific names for percent-encode sets
  - Add empty host concept for file and non-special URLs
  - Clarify IPv6 serializer
- Fix existing mistakes
  - Add missing ':' to forbidden host code point list.
  - Correct IPv4 parser empty label behavior
- Maintain type equivalence in URLContext with spec
  - scheme, username, and password should always be strings
  - host, port, query, and fragment may be strings or null
  - Align scheme state more closely with the spec
  - Make sure the `special` variable is always synced with
    URL_FLAG_SPECIAL.

PR-URL: #12523
Fixes: #10608
Fixes: #10634
Refs: whatwg/url#185
Refs: whatwg/url#225
Refs: whatwg/url#224
Refs: whatwg/url#218
Refs: whatwg/url#243
Refs: whatwg/url#260
Refs: whatwg/url#268
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
evanlucas pushed a commit to nodejs/node that referenced this pull request May 1, 2017
- Update to spec
  - Add opaque hosts
  - File state did not correctly deal with lack of base URL
  - Cleanup API for file and non-special URLs
  - Allow % and IPv6 addresses in non-special URL hosts
  - Use specific names for percent-encode sets
  - Add empty host concept for file and non-special URLs
  - Clarify IPv6 serializer
- Fix existing mistakes
  - Add missing ':' to forbidden host code point list.
  - Correct IPv4 parser empty label behavior
- Maintain type equivalence in URLContext with spec
  - scheme, username, and password should always be strings
  - host, port, query, and fragment may be strings or null
  - Align scheme state more closely with the spec
  - Make sure the `special` variable is always synced with
    URL_FLAG_SPECIAL.

PR-URL: #12523
Fixes: #10608
Fixes: #10634
Refs: whatwg/url#185
Refs: whatwg/url#225
Refs: whatwg/url#224
Refs: whatwg/url#218
Refs: whatwg/url#243
Refs: whatwg/url#260
Refs: whatwg/url#268
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
evanlucas pushed a commit to nodejs/node that referenced this pull request May 2, 2017
- Update to spec
  - Add opaque hosts
  - File state did not correctly deal with lack of base URL
  - Cleanup API for file and non-special URLs
  - Allow % and IPv6 addresses in non-special URL hosts
  - Use specific names for percent-encode sets
  - Add empty host concept for file and non-special URLs
  - Clarify IPv6 serializer
- Fix existing mistakes
  - Add missing ':' to forbidden host code point list.
  - Correct IPv4 parser empty label behavior
- Maintain type equivalence in URLContext with spec
  - scheme, username, and password should always be strings
  - host, port, query, and fragment may be strings or null
  - Align scheme state more closely with the spec
  - Make sure the `special` variable is always synced with
    URL_FLAG_SPECIAL.

PR-URL: #12523
Fixes: #10608
Fixes: #10634
Refs: whatwg/url#185
Refs: whatwg/url#225
Refs: whatwg/url#224
Refs: whatwg/url#218
Refs: whatwg/url#243
Refs: whatwg/url#260
Refs: whatwg/url#268
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
bors-servo pushed a commit to servo/rust-url that referenced this pull request Nov 6, 2017
Do not allow username,password,port for URLs without a host or file URLs

Imports tests from web-platform-tests/wpt@0e6a90f and tracks URL spec change at whatwg/url#224

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/411)
<!-- Reviewable:end -->
alice pushed a commit to alice/html that referenced this pull request Jan 8, 2019
This change builds on whatwg/url#224.

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

Location API bits are not tested since we generally treat loading from file URLs as out-of-scope for the web platform, but accounting for it standards-wise seemed trivial enough.
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.

3 participants