From fe1911ec60b9b3c56ae4fe4df4366a90cf8d32ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natalie=20Klestrup=20R=C3=B6ijezon?= Date: Fri, 15 Sep 2023 17:42:18 +0200 Subject: [PATCH] Non-ASCII input will be caught anyway, because it's never a valid character --- src/duration/mod.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/duration/mod.rs b/src/duration/mod.rs index 8bbc16e93..854ca5b64 100644 --- a/src/duration/mod.rs +++ b/src/duration/mod.rs @@ -29,8 +29,8 @@ mod serde_impl; #[derive(Debug, Snafu, PartialEq)] #[snafu(module)] pub enum DurationParseError { - #[snafu(display("invalid input, either empty or contains non-ascii characters"))] - InvalidInput, + #[snafu(display("empty input"))] + EmptyInput, #[snafu(display("unexpected character {chr:?}"))] UnexpectedCharacter { chr: char }, @@ -55,9 +55,8 @@ impl FromStr for Duration { use duration_parse_error::*; let input = s.trim(); - // An empty or non-ascii input is invalid - if input.is_empty() || !input.is_ascii() { - return Err(DurationParseError::InvalidInput); + if input.is_empty() { + return EmptyInputSnafu.fail(); } let mut chars = input.char_indices().peekable(); @@ -247,8 +246,8 @@ mod test { #[rstest] #[case("1D", DurationParseError::ParseUnitError{unit: "D".into()})] #[case("2d2", DurationParseError::NoUnit{value: 2})] - #[case("1ä", DurationParseError::InvalidInput)] - #[case(" ", DurationParseError::InvalidInput)] + #[case("1ä", DurationParseError::EmptyInput)] + #[case(" ", DurationParseError::EmptyInput)] fn parse_invalid(#[case] input: &str, #[case] expected_err: DurationParseError) { let err = Duration::from_str(input).unwrap_err(); assert_eq!(err, expected_err)