From adb9332f52b884c8b872d1c969a7841188fe3089 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 1 Aug 2019 16:58:12 -0400 Subject: regex: fix -F aho-corasick optimization It turns out that when the -F flag was used, if any of the patterns contained a regex meta character (such as `.`), then we winded up escaping the pattern first before handing it off to Aho-Corasick, which treats all patterns literally. We continue to apply band-aides here and just avoid Aho-Corasick if there is an escape in any of the literal patterns. This is unfortunate, but making this work better requires more refactoring, and the right solution is to get this optimization pushed down into the regex engine. Fixes #1334 --- tests/regression.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/regression.rs b/tests/regression.rs index 40a84654..88f2194d 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -716,3 +716,13 @@ rgtest!(r1259_drop_last_byte_nonl, |dir: Dir, mut cmd: TestCommand| { cmd = dir.command(); eqnice!("fz\n", cmd.arg("-f").arg("patterns-nl").arg("test").stdout()); }); + +// See: https://github.com/BurntSushi/ripgrep/issues/1334 +rgtest!(r1334_crazy_literals, |dir: Dir, mut cmd: TestCommand| { + dir.create("patterns", &"1.208.0.0/12\n".repeat(40)); + dir.create("corpus", "1.208.0.0/12\n"); + eqnice!( + "1.208.0.0/12\n", + cmd.arg("-Ff").arg("patterns").arg("corpus").stdout() + ); +}); -- cgit v1.2.3