diff --git a/crates/nu-path/src/dots.rs b/crates/nu-path/src/dots.rs index 8d6341cb46..c001451c68 100644 --- a/crates/nu-path/src/dots.rs +++ b/crates/nu-path/src/dots.rs @@ -60,7 +60,13 @@ pub fn expand_dots(path: impl AsRef) -> PathBuf { Component::CurDir if last_component_is_normal(&result) => { // no-op } - _ => result.push(component), + _ => { + let prev_component = result.components().last(); + if prev_component == Some(Component::RootDir) && component == Component::ParentDir { + continue; + } + result.push(component) + } } } @@ -215,11 +221,7 @@ mod test_expand_dots { #[test] fn backtrack_to_root() { let path = Path::new("/foo/bar/../../../../baz"); - let expected = if cfg!(windows) { - r"\..\..\baz" - } else { - "/../../baz" - }; + let expected = if cfg!(windows) { r"\baz" } else { "/baz" }; assert_path_eq!(expand_dots(path), expected); } }