Skip to content
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

good way to create uri with path buf? #32

Open
Decodetalkers opened this issue Dec 14, 2024 · 1 comment
Open

good way to create uri with path buf? #32

Decodetalkers opened this issue Dec 14, 2024 · 1 comment

Comments

@Decodetalkers
Copy link

Emm. I need to transport pathbuf to uri, is there proper way to do it?

@yescallop
Copy link
Owner

yescallop commented Dec 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants