mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
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:
@@ -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());
|
||||
|
||||
@@ -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"))]
|
||||
|
||||
Reference in New Issue
Block a user