diff --git a/src/path.cpp b/src/path.cpp index 2cfcb80c6..d5ab52c66 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -179,9 +179,14 @@ maybe_t path_get_cdpath(const wcstring &dir, const wcstring &wd, if (next_path.empty()) next_path = L"."; if (next_path == L"." && !wd.empty()) { // next_path is just '.', and we have a working directory, so use the wd instead. - // TODO: if next_path starts with ./ we need to replace the . with the wd. next_path = wd; } + + // If next_path starts with ./ we need to replace the . with the wd. + if (string_prefixes_string(L"./", next_path) && !wd.empty()) { + next_path = next_path.replace(0, 2, wd); + } + expand_tilde(next_path, env_vars); if (next_path.empty()) continue; diff --git a/tests/cd.in b/tests/cd.in index e70a7f902..88718c16a 100644 --- a/tests/cd.in +++ b/tests/cd.in @@ -72,6 +72,9 @@ cd $base test $PWD = $base; and echo Gone to base cd linkhome test $PWD = $base/linkhome; and echo Gone to linkhome via implicit . in CDPATH +set -g CDPATH ./ +cd $base +test $PWD = $base; and echo No crash with ./ CDPATH # cd back before removing the test directory again. cd $oldpwd diff --git a/tests/cd.out b/tests/cd.out index d3801a10a..8c786556a 100644 --- a/tests/cd.out +++ b/tests/cd.out @@ -29,3 +29,4 @@ BogusPWD test 2 succeeded Gone to linkhome via CDPATH Gone to base Gone to linkhome via implicit . in CDPATH +No crash with ./ CDPATH