Skip to content

Commit db52eac

Browse files
committed
nl: output content as bytes, not as string
1 parent 1882ff5 commit db52eac

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/uu/nl/src/nl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ fn nl<T: Read>(reader: &mut BufReader<T>, stats: &mut Stats, settings: &Settings
420420
.as_bytes(),
421421
);
422422
buf.extend(settings.number_separator.as_encoded_bytes());
423-
buf.extend(String::from_utf8_lossy(&line).as_bytes());
423+
buf.extend(&line);
424424
buf.push(b'\n');
425425

426426
writer

tests/by-util/test_nl.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,10 +796,14 @@ fn test_file_with_non_utf8_content() {
796796

797797
at.write_bytes(filename, content);
798798

799-
ucmd.arg(filename).succeeds().stdout_is(format!(
800-
" 1\ta\n 2\t{}\n 3\tb\n",
801-
String::from_utf8_lossy(invalid_utf8)
802-
));
799+
let mut expected = Vec::with_capacity(30);
800+
expected.extend(b" 1\ta\n");
801+
expected.extend(b" 2\t");
802+
expected.extend(invalid_utf8);
803+
expected.extend(b"\n");
804+
expected.extend(b" 3\tb\n");
805+
806+
ucmd.arg(filename).succeeds().stdout_is_bytes(expected);
803807
}
804808

805809
// Regression tests for issue #9132: repeated flags should use last value

0 commit comments

Comments
 (0)