Stop cd "" from crashing

Fixes #8147.
This commit is contained in:
Fabian Homborg
2021-07-17 19:00:35 +02:00
parent b0981ef6db
commit e9a793532e
2 changed files with 19 additions and 0 deletions

View File

@@ -46,6 +46,15 @@ maybe_t<int> builtin_cd(parser_t &parser, io_streams_t &streams, const wchar_t *
dir_in = maybe_dir_in->as_string();
}
if (dir_in.empty()) {
streams.err.append_format(_(L"%ls: Empty directory '%ls' does not exist\n"), cmd,
dir_in.c_str());
if (!parser.is_interactive()) streams.err.append(parser.current_line());
return STATUS_CMD_ERROR;
}
wcstring pwd = parser.vars().get_pwd_slash();
auto dirs = path_apply_cdpath(dir_in, pwd, parser.vars());
if (dirs.empty()) {

View File

@@ -218,3 +218,13 @@ __fish_test_thrash_cd |
__fish_test_thrash_cd |
__fish_test_thrash_cd |
__fish_test_thrash_cd
cd ""
# CHECKERR: cd: Empty directory '' does not exist
# CHECKERR: {{.*}}/cd.fish (line {{\d+}}):
# CHECKERR: builtin cd $argv
# CHECKERR: ^
# CHECKERR: in function 'cd' with arguments '""'
# CHECKERR: called on line {{\d+}} of file {{.*}}/cd.fish
echo $status
# CHECK: 1