-
Notifications
You must be signed in to change notification settings - Fork 139
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
Allow protocol setter to switch between special and non-special schemes #674
Comments
Isn't this rather problematic as it changes the nature of the host? How do you deal with that, reparse? Query also currently branches on "is special". |
There is a whole host of problems here (pun definitely intended) but I'm just suggesting that this is the reality of URLs and the spec might want to reflect that. We could make the protocol setter re-parse the serialized URL or something like that. |
Yeah, I guess that is what we would have to do. cc @TimothyGu |
@achristensen07 would you be able to describe the algorithm that Safari uses for the protocol setter, including the reparse step? |
The current algorithm we use is as follows ( See URL::setProtocol at https://trac.webkit.org/browser/webkit/trunk/Source/WTF/wtf/URL.cpp#L390 ):
It seems like there are restrictions around "file", reparsing the whole URL, and removal of stuff after the colon that are common to all browsers. |
I think this is possible, but can be quite tricky. IMO this operation should avoid anything which would cause other URL components to be interpreted with a different meaning, and that may require a lot of testing/fuzzing/etc to figure out. But I think it's possible. A few cases I can think of:
|
I like the idea of ensuring the parts don't get reinterpreted too much before allowing a non-special URL to switch to a special scheme. As an example, to allow switching to
To switch to
As an additional example, Firefox and Safari currently have the following behavior: u = new URL('javascript:!!notahost()');
u.protocol = 'http:';
console.assert(u.href, 'http://!!notahost()/');
// console.assert(u.href, 'http://%21%21notahost%28%29/'); // Chrome which I don't think is useful or worth keeping. It also sounds like escaping |
Not that complicated, and no need to reparse the URL. |
The alternative for switching to You’d have to adjust for the scheme dependent percent coding though. That may sound complex, but there’s a lot of advantages to defining that as an operation on URL records. It is key in recovering a formal grammar and reference resolution as per RFC 3986 for WHATWG URLs. |
I don’t have any way to take an object of properties and turn them into a URL, except |
Hi folks, We've finally shipped the special scheme to non-special scheme restriction in bug 1347459 in Firefox 117, but a regression has been reported: Bug 1850954 - Cant change URL.protocol since v117 Chrome has also landed this recently in https://bugs.chromium.org/p/chromium/issues/detail?id=1416018 , which isn't yet in release. Is there a better way for sites to change the scheme other than this?
Do we commit to this restriction or is there any intent to allow special/non-special protocol changes? |
The relevant webkit bug https://bugs.webkit.org/show_bug.cgi?id=229427 |
@ricea thoughts?
This is how we would have to do it as well, given that host fundamentally changes. So setting |
@hayatoito is handling this in Chromium and has more context than me. |
I received a question on https://bugs.chromium.org/p/chromium/issues/detail?id=1416018 and posted a reply on https://bugs.chromium.org/p/chromium/issues/detail?id=1416018#c11. I just assumed that the standard intentionally included this limitation. |
It's definitely intentional as changes to the scheme would end up changing other components as well, which is rather unexpected. Having said that, https://url.spec.whatwg.org/#potentially-strip-trailing-spaces-from-an-opaque-path does so as well so there is precedent now, but that's a very limited impact. Changing the scheme however would end up changing the host, which is central to the authority of a URL. I'd rather not do that personally if we can get away with it. |
Thanks. I currently don't intend to undo the Chrome fix, at least for now. The fix will be part of the M118 release to make Chrome align with the current URL standard, unless we encounter a significant issue. If we decide to permit setting protocols, please inform me by updating the issue or here. I thought this was a straightforward bug fix, and wasn't aware that there is on-going discussion to change the standard here. :( |
Chrome, Firefox, and Safari all agree on this behavior:
u = new URL("custom-scheme://host?initially-no-path");
u.protocol = "https";
u.protocol = "custom-scheme";
u.href; // custom-scheme://host/?initially-no-path
Even though it is a little strange, I have reason to believe that people are using the URL protocol setter to do this already.
The text was updated successfully, but these errors were encountered: