1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2024-12-12 19:18:24 +02:00

fix word boundary w/ capture group

fixes BurntSushi/ripgrep#506. Word boundary search as arg had unexpected
behavior. added capture group to regex to encapsulate 'or' option search and
prevent expansion and partial boundary finds.

Signed-off-by: Evan.Mattiza <emattiza@gmail.com>
This commit is contained in:
Evan.Mattiza 2017-06-14 22:07:55 -05:00 committed by Andrew Gallant
parent e0989ef13b
commit 06393f888c
2 changed files with 18 additions and 1 deletions

View File

@ -505,7 +505,7 @@ impl<'a> ArgMatches<'a> {
/// flag is set. Otherwise, the pattern is returned unchanged.
fn word_pattern(&self, pat: String) -> String {
if self.is_present("word-regexp") {
format!(r"\b{}\b", pat)
format!(r"\b(?:{})\b", pat)
} else {
pat
}

View File

@ -1690,6 +1690,23 @@ fn regression_483_non_matching_exit_code() {
wd.assert_err(&mut cmd);
}
// See: https://github.com/BurntSushi/ripgrep/issues/506
#[test]
fn regression_506_word_boundaries_not_parenthesized() {
let wd = WorkDir::new("regression_506_word_boundaries_not_parenthesized");
let path = "wb.txt";
wd.create(path, "min minimum amin\n\
max maximum amax");
let mut cmd = wd.command();
cmd.arg("-w").arg("min|max").arg(path).arg("--only-matching");
let lines: String = wd.stdout(&mut cmd);
let expected = "min\nmax\n";
assert_eq!(lines, expected);
}
#[test]
fn type_list() {