mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-12 20:21:15 -03:00
cd: fix path when trying to cd out of the root directory
Part of #12704
This commit is contained in:
committed by
Johannes Altmanninger
parent
d885e0efd7
commit
4f539dffaf
@@ -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. `//<path>`, which
|
||||
// on Windows, is a remote directory).
|
||||
if abspath.chars().next_back() != Some('/') {
|
||||
abspath.push('/');
|
||||
}
|
||||
}
|
||||
abspath.push_utfstr(&path);
|
||||
|
||||
|
||||
@@ -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 `<pwd>+/+<dir>` internally, when pwd is `/`, i.e.
|
||||
# results in `//<dir>`. 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
|
||||
|
||||
Reference in New Issue
Block a user