printer: fix \r\n line terminator handling

This fixes a bug where it was assumed that 'is_suffix' when CRLF
handling was enabled mean that '\r\n' was present. But that's not the
case, and it is intentional that 'is_suffix' only looks for '\n'. (Which
is why #1803 wasn't taken, which tries to fix this by changing
'is_suffix'.)

Fixes #1765, Closes #1803
This commit is contained in:
Andrew Gallant
2021-05-30 11:13:27 -04:00
parent e6cac8b119
commit 12dd455ee9
3 changed files with 41 additions and 4 deletions

View File

@@ -867,6 +867,16 @@ use B;
eqnice!("2\n", cmd.stdout());
});
// See: https://github.com/BurntSushi/ripgrep/issues/1765
rgtest!(r1765, |dir: Dir, mut cmd: TestCommand| {
dir.create("test", "\n");
// We need to add --color=always here to force the failure, since the bad
// code path is only triggered when colors are enabled.
cmd.args(&[r"x?", "--crlf", "--color", "always"]);
assert!(!cmd.stdout().is_empty());
});
rgtest!(r1866, |dir: Dir, mut cmd: TestCommand| {
dir.create("test", "foobar\nfoobar\nfoo quux");
cmd.args(&[