mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
cat: handle CRLF delimiters correctly (#6763)
* fix issue #6248 * add test to cat for the case of issue #6248
This commit is contained in:
parent
e0e3ea6996
commit
382e787d1c
2 changed files with 18 additions and 2 deletions
|
@ -540,9 +540,16 @@ fn write_new_line<W: Write>(
|
||||||
state: &mut OutputState,
|
state: &mut OutputState,
|
||||||
is_interactive: bool,
|
is_interactive: bool,
|
||||||
) -> CatResult<()> {
|
) -> CatResult<()> {
|
||||||
if state.skipped_carriage_return && options.show_ends {
|
if state.skipped_carriage_return {
|
||||||
writer.write_all(b"^M")?;
|
if options.show_ends {
|
||||||
|
writer.write_all(b"^M")?;
|
||||||
|
} else {
|
||||||
|
writer.write_all(b"\r")?;
|
||||||
|
}
|
||||||
state.skipped_carriage_return = false;
|
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 {
|
if !state.at_line_start || !options.squeeze_blank || !state.one_blank_kept {
|
||||||
state.one_blank_kept = true;
|
state.one_blank_kept = true;
|
||||||
|
|
|
@ -288,6 +288,15 @@ fn test_numbered_lines_no_trailing_newline() {
|
||||||
// spell-checker:enable
|
// 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]
|
#[test]
|
||||||
fn test_stdin_show_nonprinting() {
|
fn test_stdin_show_nonprinting() {
|
||||||
for same_param in ["-v", "-vv", "--show-nonprinting", "--show-non"] {
|
for same_param in ["-v", "-vv", "--show-nonprinting", "--show-non"] {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue