mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-06-30 22:23:44 +02:00
regex: fix matching bug when text anchors are used
It turns out that if there are text anchors (that is, \A or \z, or ^/$ when multi-line is disabled), then the "fast" line searching path isn't quite correct. Since searching without multi-line mode is exceptionally rare, we just look for the presence of text anchors and specifically disable the line terminator option in 'grep-regex'. This in turn inhibits the "fast" line searching path. Fixes #2260
This commit is contained in:
@ -52,8 +52,12 @@ impl RegexMatcherBuilder {
|
||||
|
||||
let matcher = RegexMatcherImpl::new(&chir)?;
|
||||
log::trace!("final regex: {:?}", matcher.regex());
|
||||
let mut config = self.config.clone();
|
||||
// We override the line terminator in case the configured expr doesn't
|
||||
// support it.
|
||||
config.line_terminator = chir.line_terminator();
|
||||
Ok(RegexMatcher {
|
||||
config: self.config.clone(),
|
||||
config,
|
||||
matcher,
|
||||
fast_line_regex,
|
||||
non_matching_bytes,
|
||||
|
Reference in New Issue
Block a user