-
Notifications
You must be signed in to change notification settings - Fork 141
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
file: URL with a port number through the host setter #97
Comments
@achristensen07 Safari appears to allow for host:port somehow through the host setter for file URLs. Would you consider that a bug? I tend to think we should fix this by making file URLs use the file host state. |
This is indeed a bug in my implementation. I had overlooked the fact that file URLs can't have ports and used the same host-and-port parser for file URLs as non-file URLs. We should also add a test like "new URL('file://host:45/path')" and make sure it fails. |
We should definitely either change this or allow file URLs to have a port. I'm not sure why Safari allows ports on file URLs |
The other question is what the setter should do. Should we fail on ":" or just end tokenizing there (as hostname does). And setting If we special case file URLs in |
To be clear, I don't have strong opinions here on what is best. Allowing ports to end up in file URLs doesn't seem to be the end of the world, nor would failing on ":" be. |
@sleevi do you have any thoughts here? |
Note that Firefox doesn't appear to allow setting the host of file URLs at all. |
This is a bug in the Node.js implementation also. I'll get it fixed. |
Thinking it over a bit, the spec should likely be updated to treat specifying a port for the host in a file URL as an error. Parsing a URL such as |
@annevk File URLs & ports/authority has a storied history in Chrome... attached are my notes from the last time I dug into this, to at least hopefully explain the behaviour to figure out where to align: Can "file" have a host?RFC 3986 Section 3.2.2 notes (in passing) that
If we dig back to RFC 1630, Page 18:
and
Can "file" have a port?RFC 1738, Section 3.10, which updates RFC 1630 (and became the basis for RFC 3986) notes the file scheme as:
Unlike other schemes (such as prospero or wais), which explicitly list the So to what Chrome's behaviour is:
To your question about what's the right behaviour: I suspect failing on Allowing ports on file URLs seems to have the largest back-compat issues, at least re: spec precedent - it's seemingly long been forbidden - and it's also something probably unlikely for Chrome, if only because that would require a lot more monkey-ing about with the UNC & drive-letter sniffing logic. |
@sleevi if you do |
Using "file host state" as override is not a good idea as it doesn't really deal with the possibility of being a state override well. Since a file host can be empty, setting to the empty string should work as well I guess if we care about making this fully functional... |
@annevk I'd be happy to treat that behaviour as a bug and see about fixing it in Chrome, if only because what the URL API exposes, the underlying implementation won't preserve (e.g. if you copy the object or send it across IPC boundaries, it will serialize/reparse differently) |
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.
I ended up finding quite a few issues while working through this. I hope I addressed them all in the PR. Have yet to write test coverage for all that. |
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.
When the
Url::host
setter is invoked for an URL in thefile
scheme, the parser starts in the "host state" (not the "file host state") so the URL can (per spec) end up with a non-null port number, which otherwise never happens.In this test case: http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=3927 Firefox doesn’t change the URL at all, Chromium changes the host but not the port number.
The text was updated successfully, but these errors were encountered: