diff --git a/src/path.rs b/src/path.rs index 616822fed..7ccc18102 100644 --- a/src/path.rs +++ b/src/path.rs @@ -358,7 +358,14 @@ pub fn path_apply_cdpath(dir: &wstr, wd: &wstr, env_vars: &dyn Environment) -> V // We want to return an absolute path (see issue 6220) if ![Some('/'), Some('~')].contains(&path.chars().next()) { abspath = wd.to_owned(); - abspath.push('/'); + + // Do not add a second slash if `wd` already ends with one + // (typically, when it's the root directory). + // This could result in unwanted paths (e.g. `//`, which + // on Windows, is a remote directory). + if abspath.chars().next_back() != Some('/') { + abspath.push('/'); + } } abspath.push_utfstr(&path); diff --git a/tests/checks/cd.fish b/tests/checks/cd.fish index 7e6840de8..daf3a5462 100644 --- a/tests/checks/cd.fish +++ b/tests/checks/cd.fish @@ -407,3 +407,10 @@ cd (string repeat 4096 a) # CHECKERR: ^ # CHECKERR: in function 'cd' with arguments '{{.*}}' # CHECKERR: called on line {{\d+}} of file {{.*}}/cd.fish + +# Ensures `cd` doesn't create `+/+` internally, when pwd is `/`, i.e. +# results in `//`. This test will (hopefully) fail on platforms where such +# a path has a special meaning (e.g. Windows would fail trying to access a server +# named "bin") +cd / +cd bin