1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

factor: trim the input to fix some busybox results

This commit is contained in:
Sylvestre Ledru 2022-12-05 22:49:48 +01:00
parent 72d60f0869
commit b7925465a8
2 changed files with 12 additions and 8 deletions

View file

@ -35,7 +35,11 @@ fn print_factors_str(
w: &mut io::BufWriter<impl io::Write>, w: &mut io::BufWriter<impl io::Write>,
factors_buffer: &mut String, factors_buffer: &mut String,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
num_str.parse::<u64>().map_err(|e| e.into()).and_then(|x| { num_str
.trim()
.parse::<u64>()
.map_err(|e| e.into())
.and_then(|x| {
factors_buffer.clear(); factors_buffer.clear();
writeln!(factors_buffer, "{}:{}", x, factor(x))?; writeln!(factors_buffer, "{}:{}", x, factor(x))?;
w.write_all(factors_buffer.as_bytes())?; w.write_all(factors_buffer.as_bytes())?;

View file

@ -108,10 +108,10 @@ fn test_cli_args() {
new_ucmd!().args(&["3"]).succeeds().stdout_contains("3: 3"); new_ucmd!().args(&["3"]).succeeds().stdout_contains("3: 3");
new_ucmd!() new_ucmd!()
.args(&["3", "6"]) .args(&["3", "6", " +9"])
.succeeds() .succeeds()
.stdout_contains("3: 3") .stdout_contains("3: 3")
.stdout_contains("6: 2 3"); .stdout_contains("9: 3 3");
} }
#[test] #[test]