diff --git a/src/args.rs b/src/args.rs index 068a40d5..b0e5d648 100644 --- a/src/args.rs +++ b/src/args.rs @@ -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 } diff --git a/tests/tests.rs b/tests/tests.rs index d9c843ad..95fecfd4 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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() {