-
Notifications
You must be signed in to change notification settings - Fork 334
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
Url.to_file_path() doesn't produce UNC path on Windows #450
Comments
As I understand it, the output of URL syntax doesn't really have a way to represent the distinction between Windows' extended length paths and "normal" paths, so I think it's reasonable that canonicalized paths cannot round-trip through URL encoding. |
I’m very unfamiliar with UNC, so it would help a lot if someone could write up or point to something about the different kinds of paths that exist on Windows and how they should map to Note however that “this |
As I understand it, all the actual conventions about Windows paths and Basic absolute Windows paths like UNC Windows paths like Device paths like Rust also supports a generic Verbatim prefix which is presumably for forwards-compatibility in case Microsoft introduces a path that's not a local or UNC path, but the URL library probably doesn't care about any of that. Google's Project Zero has an unofficial guide to Windows path syntaxes that mentions a TL;DR: it's probably not worth bothering with anything beyond the Disk, UNC, VerbatimDisk and VerbatimUNC.prefixes. |
Thanks @Screwtapello! Do you have thoughts on the other conversion, from |
It's hard to recommend a general plan. On one hand, the basic path syntax is the simplest, most recognizable, most compatible with other programs (for example, in a config file, or on the command-line), and allows shortcuts like "." and ".." to navigate within the path hierarchy which some URLs may expect. Also, this is the only path syntax available on non-Windows platforms. On the other hand, the extended-length syntax allows paths much longer than 256 characters (so for some URLs you'll need to use extended-length syntax no matter what the default is), and are immune to the classic "forbidden filenames" problem where trying to read or write a file named "COM1" or "AUX" or "LPT2" etc. will try to access a device and usually hang forever. The easiest and safest thing would probably be to always use extended-length path syntax on Windows, shielding apps from most of the rough corner-cases of Windows path handling. A nicer system would be to use basic syntax on Windows unless the path is longer than 256 characters, or if it mentions one of the forbidden filenames listed in the unofficial guide I linked to... but that kind of blacklisting is pretty complex and probably deserves its own crate. |
Url.to_file_path()
doesn't produce a UNC path on Windows, even when the Url was initialized with a UNC path viaUrl.from_file_path()
. Thus this program:Fails with:
It seems like
Url.to_file_path()
should produce a UNC path, at least when the Url was initialized with one; and perhaps in all cases, for compatibility with std::fs::canonicalize(), which always produces UNC paths on Windows (although this is controversial, per rust-lang/rust#42869).The text was updated successfully, but these errors were encountered: