mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-11-29 05:57:07 +02:00
printer: hack in a fix for -l/--files-with-matches when using --pcre2 --multiline with look-around
The underlying issue here is #2528, which was introduced by commit
efd9cfb2fc which fixed another bug.
For the specific case of "did a file match," we can always assume the
match count is at least 1 here. But this doesn't fix the underlying
problem.
Fixes #3139
This commit is contained in:
@@ -683,7 +683,11 @@ impl<'p, 's, M: Matcher, W: WriteColor> Sink for SummarySink<'p, 's, M, W> {
|
||||
true
|
||||
},
|
||||
)?;
|
||||
count
|
||||
// Because of `find_iter_at_in_context` being a giant
|
||||
// kludge internally, it's possible that it won't find
|
||||
// *any* matches even though we clearly know that there is
|
||||
// at least one. So make sure we record at least one here.
|
||||
count.max(1)
|
||||
};
|
||||
if is_multi_line {
|
||||
self.match_count += sink_match_count;
|
||||
|
||||
@@ -1544,3 +1544,44 @@ rgtest!(
|
||||
cmd.args(&["--files", "-g", "[abc"]).assert_err();
|
||||
}
|
||||
);
|
||||
|
||||
rgtest!(
|
||||
r3139_multiline_lookahead_files_with_matches,
|
||||
|dir: Dir, _cmd: TestCommand| {
|
||||
// Only PCRE2 supports look-around.
|
||||
if !dir.is_pcre2() {
|
||||
return;
|
||||
}
|
||||
dir.create(
|
||||
"test",
|
||||
"\
|
||||
Start \n \n\n \
|
||||
XXXXXXXXXXXXXXXXXXXXXXXXXX\n \
|
||||
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\n \
|
||||
\n thing2 \n\n",
|
||||
);
|
||||
|
||||
let got = dir
|
||||
.command()
|
||||
.args(&[
|
||||
"--multiline",
|
||||
"--pcre2",
|
||||
r"(?s)Start(?=.*thing2)",
|
||||
"test",
|
||||
])
|
||||
.stdout();
|
||||
eqnice!("Start \n", got);
|
||||
|
||||
let got = dir
|
||||
.command()
|
||||
.args(&[
|
||||
"--multiline",
|
||||
"--pcre2",
|
||||
"--files-with-matches",
|
||||
r"(?s)Start(?=.*thing2)",
|
||||
"test",
|
||||
])
|
||||
.stdout();
|
||||
eqnice!("test\n", got);
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user