Skip to content

Commit

Permalink
fix(util): Respect all ..s in normalize_path
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 30, 2024
1 parent bade608 commit 4c5537e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions crates/cargo-util/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 4c5537e

Please sign in to comment.