You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have thought about adding such an API for a very long time, but hesitate to do it because it feels like opening a can of worms. The behavior of conversion both from a path to a file URI and backward is platform-dependent, to begin with. There are also edge cases such as encoded NUL bytes or slashes. The behavior of a file URI is not consistent with that of a path either, in that double dot (..) segments in a file URI can be removed before accessing the filesystem but those in a path cannot because of the presence of symbolic links, and in that one can change the drive letter on Windows by resolving ../D:/ against the file URI file:///C:/ but not by resolving it against the path C:\.
Let me give an example to illustrate the problem. Take the path /a/../foo.txt, where /a/ is a symlink to /b/c/. The path should resolve to /b/foo.txt (by fs::canonicalize for example) if the path exists. To ensure consistent behavior, we must convert the path to the file URI file:///b/c/../foo.txt instead of file:///a/../foo.txt if the path exists, because the latter can be normalized to file:///foo.txt before being converted back to a path. But what if the path does not exist? Do we return an error in this case? Or generally, do we return an error for any path that does not exist?
It takes effort to answer these questions. Any ideas on this topic would be very welcome.
Emm. I need to transport pathbuf to uri, is there proper way to do it?
The text was updated successfully, but these errors were encountered: