Skip to content

Commit 7a6eaf9

Browse files
committed
fix(util): Respect all ..s in normalize_path
1 parent c53bdc4 commit 7a6eaf9

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

crates/cargo-util/src/paths.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ pub fn normalize_path(path: &Path) -> PathBuf {
9898
}
9999
Component::CurDir => {}
100100
Component::ParentDir => {
101-
ret.pop();
101+
if ret.ends_with(Component::ParentDir) {
102+
ret.push(Component::ParentDir);
103+
} else {
104+
let popped = ret.pop();
105+
if !popped && !ret.has_root() {
106+
ret.push(Component::ParentDir);
107+
}
108+
}
102109
}
103110
Component::Normal(c) => {
104111
ret.push(c);
@@ -879,13 +886,13 @@ mod tests {
879886
("foo/bar/./././///", "foo/bar"),
880887
("foo/bar/..", "foo"),
881888
("foo/bar/../..", ""),
882-
("foo/bar/../../..", ""),
883-
("../../foo/bar", "foo/bar"),
884-
("../../foo/bar/", "foo/bar"),
885-
("../../foo/bar/./././///", "foo/bar"),
886-
("../../foo/bar/..", "foo"),
887-
("../../foo/bar/../..", ""),
888-
("../../foo/bar/../../..", ""),
889+
("foo/bar/../../..", ".."),
890+
("../../foo/bar", "../../foo/bar"),
891+
("../../foo/bar/", "../../foo/bar"),
892+
("../../foo/bar/./././///", "../../foo/bar"),
893+
("../../foo/bar/..", "../../foo"),
894+
("../../foo/bar/../..", "../.."),
895+
("../../foo/bar/../../..", "../../.."),
889896
];
890897
for (input, expected) in cases {
891898
let actual = normalize_path(std::path::Path::new(input));

0 commit comments

Comments
 (0)