summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2023-07-31 08:51:09 -0400
committerGitHub <noreply@github.com>2023-07-31 08:51:09 -0400
commit341a19e0d05bc6f0cabeb2dc756b37cfc047f8f0 (patch)
treef6734ca5fac1f12305749131a8494078e81e7d3e /tests
parentfed4fea217abbc502f2e823465de903c8f2b623d (diff)
regex: fix fast path for -w/--word-regexp flag (#2576)
It turns out our fast path for -w/--word-regexp wasn't quite correct in some cases. Namely, we use `(?m:^|\W)(<original-regex>)(?m:\W|$)` as the implementation of -w/--word-regexp since `\b(<original-regex>)\b` has some unintuitive results in certain cases, specifically when <original-regex> matches non-word characters at match boundaries. The problem is that using this formulation means that you need to extract the capture group around <original-regex> to find the "real" match, since the surrounding (^|\W) and (\W|$) aren't part of the match. This is fine, but the capture group engine is usually slow, so we have a fast path where we try to deduce the correct match boundary after an initial match (before running capture groups). The problem is that doing this is rather tricky because it's hard to know, in general, whether the `^` or the `\W` matched. This still doesn't seem quite right overall, but we at least fix one more case. Fixes #2574
Diffstat (limited to 'tests')
-rw-r--r--tests/regression.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/regression.rs b/tests/regression.rs
index b9076803..5ef741cf 100644
--- a/tests/regression.rs
+++ b/tests/regression.rs
@@ -1173,3 +1173,18 @@ rgtest!(r2480, |dir: Dir, mut cmd: TestCommand| {
cmd.args(&["--only-matching", "-e", "(?i)notfoo", "-e", "bar", "file"]);
cmd.assert_err();
});
+
+// See: https://github.com/BurntSushi/ripgrep/issues/2574
+rgtest!(r2574, |dir: Dir, mut cmd: TestCommand| {
+ dir.create("haystack", "some.domain.com\nsome.domain.com/x\n");
+ let got = cmd
+ .args(&[
+ "--no-filename",
+ "--no-unicode",
+ "-w",
+ "-o",
+ r"(\w+\.)*domain\.(\w+)",
+ ])
+ .stdout();
+ eqnice!("some.domain.com\nsome.domain.com\n", got);
+});