diff --git a/src/expand.cpp b/src/expand.cpp index 76e3ae8e7..d28b0e9bd 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -881,6 +881,9 @@ wcstring replace_home_directory_with_tilde(const wcstring &str, const environmen if (string_prefixes_string(L"/", result)) { wcstring home_directory = L"~"; expand_tilde(home_directory, vars); + // If we can't get a home directory, don't replace anything. + // This is the case e.g. with --no-execute. + if (home_directory.empty()) return result; if (!string_suffixes_string(L"/", home_directory)) { home_directory.push_back(L'/'); } diff --git a/tests/checks/no-execute.fish b/tests/checks/no-execute.fish index 93241c58a..1e5f54e01 100644 --- a/tests/checks/no-execute.fish +++ b/tests/checks/no-execute.fish @@ -23,5 +23,14 @@ echo "begin; echo oops" | $fish -n echo $status #CHECK: 127 +echo "begin" > broken +$fish -n $PWD/broken +#CHECKERR: /{{.*}}broken (line 1): Missing end to balance this begin +#CHECKERR: begin +#CHECKERR: ^~~~^ +#CHECKERR: warning: Error while reading file /{{.*}}broken + +rm broken + # Littlecheck assumes a status of 127 means the shebang was invalid. exit 0