factor: trim also null-chars (#11182)

* fix bug #11097: factor: trim also null-chars

* for factor: add test_trim_null_chars

* test_factor: pipe_in instead of pipe_in_fixture
This commit is contained in:
Yotam Medini
2026-03-04 09:54:17 +01:00
committed by GitHub
parent 79a076e46a
commit f52e3e800b
2 changed files with 11 additions and 1 deletions
+2 -1
View File
@@ -28,7 +28,8 @@ fn write_factors_str(
w: &mut io::BufWriter<impl Write>,
print_exponents: bool,
) -> UResult<()> {
let rx = num_str.trim().parse::<BigUint>();
let trimmed = num_str.trim_matches(|c: char| c.is_whitespace() || c == '\0');
let rx = trimmed.parse::<BigUint>();
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());
+9
View File
@@ -54,6 +54,15 @@ fn test_repeated_exponents() {
.no_stderr();
}
#[test]
fn test_trim_null_chars() {
new_ucmd!()
.pipe_in("42\0")
.succeeds()
.stdout_only("42: 2 3 7\n")
.no_stderr();
}
#[test]
#[cfg(feature = "sort")]
#[cfg(not(target_os = "android"))]