-
Notifications
You must be signed in to change notification settings - Fork 20
Path::force_relative #437
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
in what cases this function will not be just trimming characters from the start?
|
it may be desirable to normalize away
yes, that will also be turned into a relative path. |
i mean could you fill in the expected results for // this is according to doc
assert_eq!(Path::new(r"../../../../etc/passwd").force_relative(), Path::new("etc/passwd"));
#[cfg(windows)] {
assert_eq!(Path::new(r"C:\PROGRA~1\Rust\rustc.exe").force_relative(), Path::new("???"));
assert_eq!(Path::new(r"\\server\share\a.txt").force_relative(), Path::new("???"));
}
#[cfg(unix)] {
// this is according to doc
assert_eq!(Path::new(r"/tmp/swap.txt").force_relative(), Path::new("tmp/swap.txt"));
assert_eq!(Path::new(r"a/b/../c/d").force_relative(), Path::new("???"));
assert_eq!(Path::new(r"/a/b/../b/c/d").force_relative(), Path::new("???"));
assert_eq!(Path::new(r"a/../b/c/d").force_relative(), Path::new("???"));
assert_eq!(Path::new(r"/a/../b/c/d").force_relative(), Path::new("???"));
assert_eq!(Path::new(r"a/../../c/d").force_relative(), Path::new("???"));
assert_eq!(Path::new(r"/a/../../c/d").force_relative(), Path::new("???"));
} |
this should be handled separately by |
This one method feels drastically underpowered for the problem statement that proposes it. I'll also add the Perhaps some form of |
what if the directory you want to isolate to is known to not contain symlinks? |
We discussed this in the @rust-lang/libs-api meeting today. We think that this use case is better addressed by #396's |
Proposal
Problem statement
It is frequently desirable to prevent creation of files outside a given directory.
Motivating examples or use cases
archive extractor programs (eg.
tar
,unzip
) usually do not allow extracting to an absolute path, instead removing the leading/
.Solution sketch
Alternatives
fs.FS
. both this and the current proposal would need additonal help to prevent symlink escapes.&Path
. saves an allocation and works for the basic case where it only needs to trim charachters from the startCow
, saving an allocation in the trimming and passthrough cases, but slightly increasing complexityLinks and related work
golang
fs.FS
tar(1), see the
--absolute-names
option.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: