1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2024-12-12 19:18:24 +02:00
ripgrep/crates
Andrew Gallant 7ed9a31819 printer: fix --count-matches output
In order to implement --count-matches, we simply re-execute the regex on
the spans reported by the searcher. The spans always correspond to the
lines that participated in the match. This is the correct thing to do,
except when the regex contains look-ahead (or look-behind).

In particular, the look-around permits the regex's match success to
depends on an arbitrary point before or after the lines actually
reported as participating in the match. Since only the matched lines are
reported to the printer, it is possible for subsequent searching on
those lines to fail.

A true fix for this would somehow make the total span available to the
printer. But that seems tricky since it isn't always available. For
PCRE2's case in multiline mode, it is available because we force it to
be so for correctness.

For now, we simply detect this corner case heuristically. If the match
count is zero, then it necessarily means there is some kind of
look-around that isn't matching. So we set the match count to 1. This is
probably incorrect in some cases, although my brain can't quite come up
with a concrete example. Nevertheless, this is strictly better than the
status quo.

Fixes #1573
2020-05-08 23:24:40 -04:00
..
cli ripgrep: release 12.0.0 2020-03-15 21:42:54 -04:00
core doc: fix newline escape 2020-04-13 08:49:27 -04:00
globset ripgrep: release 12.0.0 2020-03-15 21:42:54 -04:00
grep ripgrep: release 12.0.0 2020-03-15 21:42:54 -04:00
ignore crates/ignore: switch to depth first traversal 2020-04-18 11:33:03 -04:00
matcher ripgrep: release 12.0.0 2020-03-15 21:42:54 -04:00
pcre2 ripgrep: release 12.0.0 2020-03-15 21:42:54 -04:00
printer printer: fix --count-matches output 2020-05-08 23:24:40 -04:00
regex regex: fix another inner literal bug 2020-04-01 20:37:48 -04:00
searcher ripgrep: release 12.0.0 2020-03-15 21:42:54 -04:00