cat: handle CRLF delimiters correctly (#6763)

* fix issue #6248

* add test to cat for the case of issue #6248
This commit is contained in:
Peng Zijun
2024-10-02 15:15:06 +02:00
committed by GitHub
parent e0e3ea6996
commit 382e787d1c
2 changed files with 18 additions and 2 deletions
+9 -2
View File
@@ -540,9 +540,16 @@ fn write_new_line<W: Write>(
state: &mut OutputState,
is_interactive: bool,
) -> CatResult<()> {
if state.skipped_carriage_return && options.show_ends {
writer.write_all(b"^M")?;
if state.skipped_carriage_return {
if options.show_ends {
writer.write_all(b"^M")?;
} else {
writer.write_all(b"\r")?;
}
state.skipped_carriage_return = false;
write_end_of_line(writer, options.end_of_line().as_bytes(), is_interactive)?;
return Ok(());
}
if !state.at_line_start || !options.squeeze_blank || !state.one_blank_kept {
state.one_blank_kept = true;
+9
View File
@@ -288,6 +288,15 @@ fn test_numbered_lines_no_trailing_newline() {
// spell-checker:enable
}
#[test]
fn test_numbered_lines_with_crlf() {
new_ucmd!()
.args(&["-n"])
.pipe_in("Hello\r\nWorld")
.succeeds()
.stdout_only(" 1\tHello\r\n 2\tWorld");
}
#[test]
fn test_stdin_show_nonprinting() {
for same_param in ["-v", "-vv", "--show-nonprinting", "--show-non"] {