diff --git a/CHANGELOG.md b/CHANGELOG.md index 58c35064c..d7d16a0d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ Bug fixes: Disable mmap searching in all non-64-bit environments. * [BUG #2236](https://github.com/BurntSushi/ripgrep/issues/2236): Fix gitignore parsing bug where a trailing `\/` resulted in an error. +* [BUG #2480](https://github.com/BurntSushi/ripgrep/issues/2480): + Fix bug when using inline regex flags with `-e/--regexp`. * [BUG #2523](https://github.com/BurntSushi/ripgrep/issues/2523): Make executable searching take `.com` into account on Windows. diff --git a/tests/regression.rs b/tests/regression.rs index e2c56968a..1cc7d5a20 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -1126,3 +1126,37 @@ rgtest!(r2236, |dir: Dir, mut cmd: TestCommand| { dir.create("foo/bar", "test\n"); cmd.args(&["test"]).assert_err(); }); + +// See: https://github.com/BurntSushi/ripgrep/issues/2480 +rgtest!(r2480, |dir: Dir, mut cmd: TestCommand| { + dir.create("file", "FooBar\n"); + + // no regression in empty pattern behavior + cmd.args(&["-e", "", "file"]); + eqnice!("FooBar\n", cmd.stdout()); + + // no regression in single pattern behavior + let mut cmd = dir.command(); + cmd.args(&["-e", ")(", "file"]); + eqnice!("FooBar\n", cmd.stdout()); + + // no regression in multiple patterns behavior + let mut cmd = dir.command(); + cmd.args(&["--only-matching", "-e", "Foo", "-e", "Bar", "file"]); + eqnice!("Foo\nBar\n", cmd.stdout()); + + // no regression in capture groups behavior + let mut cmd = dir.command(); + cmd.args(&["-e", "Fo(oB)a(r)", "--replace", "${0}_${1}_${2}${3}", "file"]); + eqnice!("FooBar_oB_r\n", cmd.stdout()); // note: ${3} expected to be empty + + // flag does not leak into next pattern on match + let mut cmd = dir.command(); + cmd.args(&["--only-matching", "-e", "(?i)foo", "-e", "bar", "file"]); + eqnice!("Foo\n", cmd.stdout()); + + // flag does not leak into next pattern on mismatch + let mut cmd = dir.command(); + cmd.args(&["--only-matching", "-e", "(?i)notfoo", "-e", "bar", "file"]); + cmd.assert_err(); +});