Skip to content
Myr

search: fix -F and -f interaction bug

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by Andrew Gallant · committed by Andrew Gallant · parent f3164f2 · Browse files · 3 files+40 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+40 added−6 removed

  • tests:+22 added−0 removed
  • other:+18 added−6 removed

3 files+40 added−6 removed

modified:src/args.rs+16 added-6 removed
1269 unmodified lines
1270 }1271 if let Some(paths) = self.values_of_os("file") {1272 for path in paths {1273 if path == "-" {1274 pats.extend(cli::patterns_from_stdin()?);1274 pats.extend(cli::patterns_from_stdin()?1275 .into_iter()1276 .map(|p| self.pattern_from_string(p))1277 );1278 } else {1276 pats.extend(cli::patterns_from_path(path)?);1279 pats.extend(cli::patterns_from_path(path)?1280 .into_iter()1281 .map(|p| self.pattern_from_string(p))1282 );1283 }1284 }1285 }1286 Ok(pats)
20 unmodified lines
13071308 /// Converts a &str pattern to a String pattern. The pattern is escaped1309 /// if -F/--fixed-strings is set.1310 fn pattern_from_str(&self, pat: &str) -> String {1305 let litpat = self.pattern_literal(pat.to_string());1306 let s = self.pattern_line(litpat);1311 self.pattern_from_string(pat.to_string())1312 }13131314 /// Applies additional processing on the given pattern if necessary1315 /// (such as escaping meta characters or turning it into a line regex).1316 fn pattern_from_string(&self, pat: String) -> String {1317 let pat = self.pattern_line(self.pattern_literal(pat));1308 if s.is_empty() {1318 if pat.is_empty() {1319 self.pattern_empty()1320 } else {1311 s1321 pat1322 }1323 }13241325 /// Returns the given pattern as a line pattern if the -x/--line-regexp
340 unmodified lines
modified:tests/regression.rs+22 added
670 unmodified lines
671 dir.create_dir("a");672 dir.create("a/foo", "test");673 cmd.arg("test").assert_err();674});675676// See: https://github.com/BurntSushi/ripgrep/issues/1176677rgtest!(r1176_literal_file, |dir: Dir, mut cmd: TestCommand| {678 dir.create("patterns", "foo(bar\n");679 dir.create("test", "foo(bar");680681 eqnice!(682 "foo(bar\n",683 cmd.arg("-F").arg("-f").arg("patterns").arg("test").stdout()684 );685});686687// See: https://github.com/BurntSushi/ripgrep/issues/1176688rgtest!(r1176_line_regex, |dir: Dir, mut cmd: TestCommand| {689 dir.create("patterns", "foo\n");690 dir.create("test", "foobar\nfoo\nbarfoo\n");691692 eqnice!(693 "foo\n",694 cmd.arg("-x").arg("-f").arg("patterns").arg("test").stdout()695 );696});
modified:CHANGELOG.md+2 added
51 unmodified lines
52* [BUG #1173](https://github.com/BurntSushi/ripgrep/issues/1173):53 Fix handling of `**` patterns in gitignore files.54* [BUG #1174](https://github.com/BurntSushi/ripgrep/issues/1174):55 Fix handling of repeated `**` patterns in gitignore files.56* [BUG #1176](https://github.com/BurntSushi/ripgrep/issues/1176):57 Fix bug where `-F`/`-x` weren't applied to patterns given via `-f`.5859600.10.0 (2018-09-07)61===================
1013 unmodified lines