-
Notifications
You must be signed in to change notification settings - Fork 20
Add normalize_lexically to Path
#396
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
Comments
Path
API with some useful helper functions.Path
I've updated this ACP based on notes from the libs-api meeting. It concentrates on what I'm now calling |
Should this normalize all separators to |
I think that is implied by "in addition to the usual normalization that the |
I've added that link to the ACP. I've also added some links for other languages. |
I've checked all linked implementation from other languages and they all behave the same regarding left-over
|
Depending on application it'd probably be safer to have some sort of E.g. https://docs.rs/safe-path/0.1.0/safe_path/fn.scoped_resolve.html |
We discussed this in the @rust-lang/libs-api meeting today. We're happy to accept this with one slight modification: empty paths should just be allowed as-is rather than erroring. Errors should only be when trying to We recognize that the behavior of erroring differs from other languages, but we believe that this behavior is more useful in practice for path validation. |
Proposal
Problem statement
For Unix platforms, we take pains to warn about the dangers of naively resolving
..
components (i.e. resolving /path/to/../file as /path/file). However, that doesn't mean it's never useful. Sometimes when working within a subdirectory we don't intend to follow..
links. Also people have a habit of using a literal..
when they really did meanpop()
. If nothing else, providing a function for this case can be a good hook to add documentation on the issue in a central location.Motivating examples or use cases
Say you have a base path and you want the user to be able to use paths below it.
Solution sketch
Have a function that removes
..
components from the path, in addition to the usual normalization that thecomponents
iterator does (such as normalizing separators).Or:
Either way, this would return an error if the
Path
contains left over..
components. I.e.path\..\..\to\file
resolves to..\to\file
. It could also error if it resolves to the empty path (less sure about this but unexpectedly empty paths can be a footgun).Alternatives
Result
, we could collect any left over..
components and place them at the beginning of the path.Links and related work
..
components lexically from a user provided path.lexically_normal
,lexically_relative
andlexically_proximate
normalize
clean
normalize
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: