diff --git a/fish-rust/src/wildcard.rs b/fish-rust/src/wildcard.rs index c150acc46..de261c713 100644 --- a/fish-rust/src/wildcard.rs +++ b/fish-rust/src/wildcard.rs @@ -667,8 +667,10 @@ mod expander { } if !self.flags.contains(ExpandFlags::FOR_COMPLETIONS) { - // Trailing slash and not accepting incomplete, e.g. `echo /xyz/`. Insert this file, we already know it exists! - self.add_expansion_result(base_dir.to_owned()); + // Trailing slash and not accepting incomplete, e.g. `echo /xyz/`. Insert this file after checking it exists. + if waccess(base_dir, F_OK) == 0 { + self.add_expansion_result(base_dir.to_owned()); + } return; } // Trailing slashes and accepting incomplete, e.g. `echo /xyz/`. Everything is added. diff --git a/tests/checks/wildcard.fish b/tests/checks/wildcard.fish index 189d6dff7..ee9e4d667 100644 --- a/tests/checks/wildcard.fish +++ b/tests/checks/wildcard.fish @@ -11,6 +11,11 @@ touch ./b/file.txt set dirs ./a ./b echo $dirs/*.txt # CHECK: ./b/file.txt +echo */foo/ +# CHECKERR: checks/wildcard.fish (line {{\d+}}): No matches for wildcard '*/foo/'. See `help wildcards-globbing`. +# CHECKERR: echo */foo/ +# CHECKERR: ^~~~~^ + cd $oldpwd rm -Rf $dir