diff options
author | Andrew Gallant <jamslam@gmail.com> | 2019-01-26 16:00:43 -0500 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2019-01-26 16:01:52 -0500 |
commit | 0df71240ff19fe8fa278b64d8776725f0253bcf9 (patch) | |
tree | 2e10221efb7c2e8b17808f46af78e52a604eb1b9 /src | |
parent | f3164f2615ce18d3ea7b5ce122dfe2a381d1b3f4 (diff) |
search: fix -F and -f interaction bug
This fixes what appears to be a pretty egregious regression where the
`-F/--fixed-strings` flag wasn't be applied to patterns supplied via
the `-f/--file` flag. The same bug existed for the `-x/--line-regexp`
flag as well, which we fix here.
Fixes #1176
Diffstat (limited to 'src')
-rw-r--r-- | src/args.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/args.rs b/src/args.rs index fed8ea60..c9f2405b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1271,9 +1271,15 @@ impl ArgMatches { if let Some(paths) = self.values_of_os("file") { for path in paths { if path == "-" { - pats.extend(cli::patterns_from_stdin()?); + pats.extend(cli::patterns_from_stdin()? + .into_iter() + .map(|p| self.pattern_from_string(p)) + ); } else { - pats.extend(cli::patterns_from_path(path)?); + pats.extend(cli::patterns_from_path(path)? + .into_iter() + .map(|p| self.pattern_from_string(p)) + ); } } } @@ -1302,13 +1308,17 @@ impl ArgMatches { /// Converts a &str pattern to a String pattern. The pattern is escaped /// if -F/--fixed-strings is set. fn pattern_from_str(&self, pat: &str) -> String { - let litpat = self.pattern_literal(pat.to_string()); - let s = self.pattern_line(litpat); + self.pattern_from_string(pat.to_string()) + } - if s.is_empty() { + /// Applies additional processing on the given pattern if necessary + /// (such as escaping meta characters or turning it into a line regex). + fn pattern_from_string(&self, pat: String) -> String { + let pat = self.pattern_line(self.pattern_literal(pat)); + if pat.is_empty() { self.pattern_empty() } else { - s + pat } } |