mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
fix(util): Respect all ..
s in normalize_path
This commit is contained in:
parent
c53bdc4745
commit
7a6eaf9667
@ -98,7 +98,14 @@ pub fn normalize_path(path: &Path) -> PathBuf {
|
||||
}
|
||||
Component::CurDir => {}
|
||||
Component::ParentDir => {
|
||||
ret.pop();
|
||||
if ret.ends_with(Component::ParentDir) {
|
||||
ret.push(Component::ParentDir);
|
||||
} else {
|
||||
let popped = ret.pop();
|
||||
if !popped && !ret.has_root() {
|
||||
ret.push(Component::ParentDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
Component::Normal(c) => {
|
||||
ret.push(c);
|
||||
@ -879,13 +886,13 @@ mod tests {
|
||||
("foo/bar/./././///", "foo/bar"),
|
||||
("foo/bar/..", "foo"),
|
||||
("foo/bar/../..", ""),
|
||||
("foo/bar/../../..", ""),
|
||||
("../../foo/bar", "foo/bar"),
|
||||
("../../foo/bar/", "foo/bar"),
|
||||
("../../foo/bar/./././///", "foo/bar"),
|
||||
("../../foo/bar/..", "foo"),
|
||||
("../../foo/bar/../..", ""),
|
||||
("../../foo/bar/../../..", ""),
|
||||
("foo/bar/../../..", ".."),
|
||||
("../../foo/bar", "../../foo/bar"),
|
||||
("../../foo/bar/", "../../foo/bar"),
|
||||
("../../foo/bar/./././///", "../../foo/bar"),
|
||||
("../../foo/bar/..", "../../foo"),
|
||||
("../../foo/bar/../..", "../.."),
|
||||
("../../foo/bar/../../..", "../../.."),
|
||||
];
|
||||
for (input, expected) in cases {
|
||||
let actual = normalize_path(std::path::Path::new(input));
|
||||
|
Loading…
x
Reference in New Issue
Block a user