From dd027abf44e3cdf39f0196255ff1dd0cbe2ac17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Sat, 14 Sep 2024 13:13:54 -0300 Subject: [PATCH 1/2] types: duration: Deal with empty as PT0S MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- xsd-types/src/types/duration.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xsd-types/src/types/duration.rs b/xsd-types/src/types/duration.rs index 8ff29a27..ccaffbe1 100644 --- a/xsd-types/src/types/duration.rs +++ b/xsd-types/src/types/duration.rs @@ -97,6 +97,11 @@ impl FromStr for Duration { let mut dur: Duration = Default::default(); let mut context = ParsingContext::new(); + + if s.is_empty() { + return Ok(dur); + } + for (i, c) in s.chars().enumerate() { match c { '-' => { From f37004eefdddb7387de370d3137edf3617541b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Sat, 14 Sep 2024 13:14:10 -0300 Subject: [PATCH 2/2] types: duration: Add test for empty string and PT0S MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- xsd-types/src/types/duration.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xsd-types/src/types/duration.rs b/xsd-types/src/types/duration.rs index ccaffbe1..d8f5f566 100644 --- a/xsd-types/src/types/duration.rs +++ b/xsd-types/src/types/duration.rs @@ -301,6 +301,8 @@ mod tests { #[test] fn duration_parsing_test() { + assert_eq!(Duration::from_str(""), Duration::from_str("PT0S")); + check_valid("PT0S"); check_valid("P2Y6M5DT12H35M30S"); check_valid("P1DT2H"); check_valid("P20M");