diff --git a/src/parse.rs b/src/parse.rs index a5cca5b..218fe8b 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -10,9 +10,7 @@ impl std::str::FromStr for ByteSize { let number = take_while(value, |c| c.is_ascii_digit() || c == '.'); match number.parse::() { Ok(v) => { - let suffix = skip_while(value, |c| { - c.is_whitespace() || c.is_ascii_digit() || c == '.' - }); + let suffix = skip_while(&value[number.len()..], char::is_whitespace); match suffix.parse::() { Ok(u) => Ok(Self((v * u) as u64)), Err(error) => Err(format!( @@ -220,6 +218,11 @@ mod tests { assert!(parse("").is_err()); assert!(parse("a124GB").is_err()); + assert!(parse("1.3 42.0 B").is_err()); + assert!(parse("1.3 ... B").is_err()); + // The original implementation did not account for the possibility that users may + // use whitespace to visually separate digits, thus treat it as an error + assert!(parse("1 000 B").is_err()); } #[test]