Join GitHub today
URL.pathname getter for file URLs produces odd result on Windows #103
The getter for URL.pathname always prefixes the pathname with /
That produces odd results in Windows:
parser.href = "file:///C:/Folder/File4.txt"
On Mac/*nix platforms parser.pathname returns a valid OS pathname. On Windows the returned pathname doesn't appear to be a valid OS pathname:
Looks like URL standard behaviour matches Chrome/Firefox but not IE11 where .pathname returns "C:/Folder/File4.txt".
Thinking about it a bit more I'm not convinced parser.pathname is always a valid OS pathname on Mac/*nix either when special filename characters (e.g. $ or *) or unicode sequences are present in the URL.
There are use cases where paths represented as file URLs need turned into local OS paths (e.g. for FileAPI and server-side JS).
Does the URL interface need another property/method to handle this? .NET has URI.LocalPath for this purpose; Cocoa has NSURL.path which can be passed to other Cocoa file APIs.
Seems like there should be an API for this somewhere (even if it's not in the URL interface) since there's a long history of security issues caused by path parsing vulnerabilities.
Apologies for the belated reply. It seems like all browsers agree here. Do you have a case where the output of the URL parser is not suitable somehow? It deals with Unicode and most "special" code points.
It's also a little unclear where something like LocalPath would be used, even if we figure out what it should do, which is a little unclear to me.