mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-03-03 14:32:22 +02:00
printer: trim line terminator before doing replacements
This is basically the same bug as #1401, but applied to replacements instead of --only-matching. Fixes #1739
This commit is contained in:
parent
af8b27ffae
commit
fbb2cfed28
@ -69,6 +69,8 @@ Bug fixes:
|
|||||||
|
|
||||||
* [BUG #1277](https://github.com/BurntSushi/ripgrep/issues/1277):
|
* [BUG #1277](https://github.com/BurntSushi/ripgrep/issues/1277):
|
||||||
Document cygwin path translation behavior in the FAQ.
|
Document cygwin path translation behavior in the FAQ.
|
||||||
|
* [BUG #1739](https://github.com/BurntSushi/ripgrep/issues/1739):
|
||||||
|
Fix bug where replacements were buggy if the regex matched a line terminator.
|
||||||
* [BUG #1311](https://github.com/BurntSushi/ripgrep/issues/1311):
|
* [BUG #1311](https://github.com/BurntSushi/ripgrep/issues/1311):
|
||||||
Fix multi-line bug where a search & replace for `\n` didn't work as expected.
|
Fix multi-line bug where a search & replace for `\n` didn't work as expected.
|
||||||
* [BUG #1401](https://github.com/BurntSushi/ripgrep/issues/1401):
|
* [BUG #1401](https://github.com/BurntSushi/ripgrep/issues/1401):
|
||||||
|
@ -68,7 +68,13 @@ impl<M: Matcher> Replacer<M> {
|
|||||||
subject = &subject[..range.end + MAX_LOOK_AHEAD];
|
subject = &subject[..range.end + MAX_LOOK_AHEAD];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
subject = &subject[..range.end];
|
// When searching a single line, we should remove the line
|
||||||
|
// terminator. Otherwise, it's possible for the regex (via
|
||||||
|
// look-around) to observe the line terminator and not match
|
||||||
|
// because of it.
|
||||||
|
let mut m = Match::new(0, range.end);
|
||||||
|
trim_line_terminator(searcher, subject, &mut m);
|
||||||
|
subject = &subject[..m.end()];
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let &mut Space { ref mut dst, ref mut caps, ref mut matches } =
|
let &mut Space { ref mut dst, ref mut caps, ref mut matches } =
|
||||||
|
@ -945,6 +945,13 @@ rgtest!(r1638, |dir: Dir, mut cmd: TestCommand| {
|
|||||||
eqnice!("foo:1:1:x\n", cmd.arg("--column").arg("x").stdout());
|
eqnice!("foo:1:1:x\n", cmd.arg("--column").arg("x").stdout());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// See: https://github.com/BurntSushi/ripgrep/issues/1739
|
||||||
|
rgtest!(r1739_replacement_lineterm_match, |dir: Dir, mut cmd: TestCommand| {
|
||||||
|
dir.create("test", "a\n");
|
||||||
|
cmd.args(&[r"-r${0}f", r".*", "test"]);
|
||||||
|
eqnice!("af\n", cmd.stdout());
|
||||||
|
});
|
||||||
|
|
||||||
// See: https://github.com/BurntSushi/ripgrep/issues/1765
|
// See: https://github.com/BurntSushi/ripgrep/issues/1765
|
||||||
rgtest!(r1765, |dir: Dir, mut cmd: TestCommand| {
|
rgtest!(r1765, |dir: Dir, mut cmd: TestCommand| {
|
||||||
dir.create("test", "\n");
|
dir.create("test", "\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user