mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-19 06:03:48 -07:00
ripgrep: fix bug when CWD has directory named -
Specifically, when searching stdin, if the current directory has a directory named `-`, then the `--with-filename` flag would automatically be turned on. This is because `--with-filename` is automatically enabled when ripgrep is given a single path that is a directory. When ripgrep is given empty arguments, and if it is searching stdin, then its default path list is just simple `["-"]`. The `is_dir` check passes, and `--with-filename` gets enabled. This commit fixes the problem by checking whether the path is `-` first. If so, then we assume it isn't a directory. This is fine, since if it is a directory and one asks to search it explicitly, then ripgrep will interpret `-` as stdin anyway (which is arguably a bug on its own, but probably not one worth fixing). Fixes #1223, Closes #1292
This commit is contained in:
committed by
Andrew Gallant
parent
c2cb0a4de4
commit
9268ff8e8d
@@ -1594,10 +1594,11 @@ impl ArgMatches {
|
||||
if self.is_present("no-filename") {
|
||||
false
|
||||
} else {
|
||||
let path_stdin = Path::new("-");
|
||||
self.is_present("with-filename")
|
||||
|| self.is_present("vimgrep")
|
||||
|| paths.len() > 1
|
||||
|| paths.get(0).map_or(false, |p| p.is_dir())
|
||||
|| paths.get(0).map_or(false, |p| p != path_stdin && p.is_dir())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user