Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/uu/factor/src/factor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
9 changes: 9 additions & 0 deletions tests/by-util/test_factor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
Loading