From 7d1d8caf93ea93eba6d1a59d60c5d8aade70764f Mon Sep 17 00:00:00 2001 From: Yotam Medini Date: Mon, 2 Mar 2026 20:32:35 +0200 Subject: [PATCH 1/3] fix bug #11097: factor: trim also null-chars --- src/uu/factor/src/factor.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uu/factor/src/factor.rs b/src/uu/factor/src/factor.rs index 898679893c9..3fe461e016d 100644 --- a/src/uu/factor/src/factor.rs +++ b/src/uu/factor/src/factor.rs @@ -28,7 +28,8 @@ fn write_factors_str( w: &mut io::BufWriter, print_exponents: bool, ) -> UResult<()> { - let rx = num_str.trim().parse::(); + let trimmed = num_str.trim_matches(|c: char| c.is_whitespace() || c == '\0'); + let rx = trimmed.parse::(); let Ok(x) = rx else { // return Ok(). it's non-fatal and we should try the next number. show_warning!("{}: {}", num_str.maybe_quote(), rx.unwrap_err()); From 5616bfbb454b2f94c3ad1b8b202954d15f139e63 Mon Sep 17 00:00:00 2001 From: Yotam Medini Date: Tue, 3 Mar 2026 21:28:10 +0200 Subject: [PATCH 2/3] for factor: add test_trim_null_chars --- tests/by-util/test_factor.rs | 9 +++++++++ tests/fixtures/factor/42_with_null_char.txt | Bin 0 -> 4 bytes 2 files changed, 9 insertions(+) create mode 100644 tests/fixtures/factor/42_with_null_char.txt diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index 79c038bdab4..89d0bcc9e0c 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -54,6 +54,15 @@ fn test_repeated_exponents() { .no_stderr(); } +#[test] +fn test_trim_null_chars() { + new_ucmd!() + .pipe_in_fixture("42_with_null_char.txt") + .succeeds() + .stdout_only("42: 2 3 7\n") + .no_stderr(); +} + #[test] #[cfg(feature = "sort")] #[cfg(not(target_os = "android"))] diff --git a/tests/fixtures/factor/42_with_null_char.txt b/tests/fixtures/factor/42_with_null_char.txt new file mode 100644 index 0000000000000000000000000000000000000000..bf03ccad65f2b22e0633e600edaf1fad35e57a06 GIT binary patch literal 4 LcmXppV&DP*0dxRy literal 0 HcmV?d00001 From 5751530bdee0eb7d9a1c91844975a9a47bfd2a23 Mon Sep 17 00:00:00 2001 From: Yotam Medini Date: Wed, 4 Mar 2026 10:16:20 +0200 Subject: [PATCH 3/3] test_factor: pipe_in instead of pipe_in_fixture --- tests/by-util/test_factor.rs | 2 +- tests/fixtures/factor/42_with_null_char.txt | Bin 4 -> 0 bytes 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 tests/fixtures/factor/42_with_null_char.txt diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index 89d0bcc9e0c..d4360bd7110 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -57,7 +57,7 @@ fn test_repeated_exponents() { #[test] fn test_trim_null_chars() { new_ucmd!() - .pipe_in_fixture("42_with_null_char.txt") + .pipe_in("42\0") .succeeds() .stdout_only("42: 2 3 7\n") .no_stderr(); diff --git a/tests/fixtures/factor/42_with_null_char.txt b/tests/fixtures/factor/42_with_null_char.txt deleted file mode 100644 index bf03ccad65f2b22e0633e600edaf1fad35e57a06..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4 LcmXppV&DP*0dxRy