diff options
author | Ninan John <jninan@thoughtworks.com> | 2019-06-05 21:03:52 +0530 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2019-08-01 17:27:23 -0400 |
commit | 9268ff8e8db179a484810cfbc40f3a8dba74ccaf (patch) | |
tree | 1c3dce162794783bbc7c9faf7fe40a75a0351786 /src/args.rs | |
parent | c2cb0a4de4597c8f911c8ebece6aa0435ef5da6f (diff) |
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
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/args.rs b/src/args.rs index 09f924dc..63526889 100644 --- a/src/args.rs +++ b/src/args.rs @@ -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()) } } } |