-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Whatwg protocol setter only seems to support special schemes #13523
Comments
/cc @nodejs/url |
By spec you are not allowed to change a special-scheme URL to a non-special-scheme, or vice versa. See scheme state step 2.1.1-2. However you can change from one special scheme to another (as you have found out), or from one non-special scheme to another: const { URL } = require('url');
const url = new URL('s3://foo.bar');
url.protocol = 's4';
url.toString(); // => s4://foo.bar The spec change was made in whatwg/url@5533c8d. See there for more details about it. |
Isn't this a bug in node's URL docs, or do they mention this special case? |
Not a bug as much as not documented. The docs can be expanded. |
Reopening as a request to document this then. |
@TimothyGu Are you sure that's how the spec is to be interpreted? My reading of https://url.spec.whatwg.org/#scheme-state, indicates that the parse method should only return in cases where It's worth noting that Chrome does not have this issue/behavior. It sets the scheme regardless In practice, I would argue that silently failing to do what is very obviously the desired action here (change the protocol) is arguably the worst behavior possible. At a minimum, there should be a console warning of some sort, probably even an thrown exception. I know this is probably more appropriate for discussion on the WhatWG forum, but this just wasted an hour and a half of my time and I'm not interested in throwing any more of my time into that particular sink hole. |
Yes, and:
Then it is Chrome's bug for not implementing whatwg/url@5533c8d.
While I'm not exactly a huge fan of silently ignoring errors, we are unfortunately in a bind here, as that is what browsers as well as the URL Standard are doing for all other attributes (for example, setting |
What about this?
Since Node isn't HTML, doesn't this mean "no state override"? |
You have to take the entire quote into context:
It's my belief that the |
ping @domenic ... thoughts on this? |
@TimothyGu's got it right. You can always add console warnings, however; those are not governed by any spec. |
Why would the spec make an exemption ("only for use by various APIs") that is meant to be interpreted as "every API implementing the URL interface"? That seems... incongruous. Getting back to what you wrote previously about [lack of] error reporting ...
That seems at odds with the spec. For example, for port state (and most other URL components addressed in the parsing verbiage) we see the phrase "validation error, return failure":
Under validation error we have (emphasis mine) :
Doesn't that pretty clearly say that user agents should not fail silently?
@domenic, who were you addressing with this comment? 'Not sure if you were suggesting the URL api should warn in this case, or if consumers of the API should be left to their own devices to figure out how to implement the warning. |
Algorithms in spec-land have two primary consumers:
For WHATWG/W3C specs at least, when they refer to "APIs" the JavaScript part is implied, so by "various APIs" they mean "not other algorithms but something directly observable from JS." And no, not only every API implementing the URL interface but the
(I'll address "validation error later...) Usually it is the "return failure" part that makes the JS function throw. Indeed, the
On the other hand, most attribute setters (other than
Note that unlike JS, failures don't bubble up automatically in specs (this is true even for the ECMAScript spec).
"encouraged to" ≠ "must". In fact, none of the browsers I tested (Firefox and Chrome) have any indication for validation errors. But even if we were to implement validation errors, we would have nowhere to show them. @domenic suggested console warnings, but that can be considered to be fairly spammy. I guess we could add some |
@TimothyGu , I appreciate your patience and explanations here. I'm content to let this die, but can you explain why this distinction between special and non-special schemes is important? I'm genuinely puzzled by how arbitrary this feels. You've said it's important to DOM APIs like One thing that's surprising to me is that, if there's a line to be drawn, I would expect it to be between secure .vs. insecure schemes like |
@broofa It can be gleaned from whatwg/url@d5470b8 and whatwg mailing list that initially "special scheme" are meant to be those that
The same e-mail mentions:
I'm sure @annevk (author of the aforementioned email and spec changes), @domenic, and the WHATWG bug tracker can give more insightful explanations. |
The main reason we have "special schemes" is because URL parsers in browsers historically (and some to this day) are more per-scheme than they are generic across all URLs. That has led to subtle things being allowed for what the URL Standard calls "special schemes" that are now hard to remove as you'd break the web. So it's basically a special case necessary for compatibility and to be able to move everyone to generic URL parsers. |
I follow this with interest. One of the complaints about node's traditional
URL could throw exceptions. Its not how browsers work, but browsers discard unhandled exceptions. As @mikeal has pointed out in the discussion about Promises, node chose to diverge from browser behaviour with unhandled exceptions, something that is generally considered a strength of node, not a weakness. |
If there is sufficient interest it might be worth considering adding something like |
I am definitely very -1 on adding validation errors that are not implemented in browsers or defined by the spec. I'd be +1 to updating the spec if necessary. |
We already throw exceptions for many fatal errors ("return failure" in spec-speak), but "validation errors" denote a class of URLs that are not strictly correct but still commonly seen in the wild and reasonably well-formed. In other words, we are already stricter than I think deviating from browser behavior by throwing validation errors in the URL parser is much less justifiable than Promises handling, which is implicated directly by what Node.js is and is not. However, as mentioned above, I do think adding appropriate Also of note is that this issue is about attribute setters, not the initial parsing step, as the conversation seems to have veered towards. |
#13523 (comment) would be useful then, @annevk's suggestion. |
@TimothyGu @jasnell Should this stay open? I read through the thread but unclear on whether anything actionable came out or was taken to the spec side? |
Currently the new whatwg url class doesn't seem to work with any other scheme except so called 'special schemes' in the spec:
https://url.spec.whatwg.org/
E.g. this works:
But this doesn't work:
Even schemes defined here: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml don't work.
Not that this does work:
The text was updated successfully, but these errors were encountered: