From 6938e305ba6624aeb1c855f77a861ad153545173 Mon Sep 17 00:00:00 2001 From: Nghia Date: Thu, 2 May 2024 07:14:48 +0200 Subject: [PATCH] fix(song/parse): fix date input have less than 4 chars (#197) --- src/utils/song/parse/tag.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils/song/parse/tag.rs b/src/utils/song/parse/tag.rs index f17df4fe..6e34bb91 100644 --- a/src/utils/song/parse/tag.rs +++ b/src/utils/song/parse/tag.rs @@ -102,7 +102,9 @@ impl<'a> From<&'a MediaDateMbz> for albums::NewAlbum<'a> { impl SongDate { #[instrument(err(Debug))] pub fn parse(input: Option<&str>) -> Result { - if let Some(input) = input { + if let Some(input) = input + && input.len() >= 4 + { let mut parsed = time::parsing::Parsed::new(); if input.len() >= 10 { // yyyy-mm-dd @@ -262,6 +264,9 @@ mod tests { let date = SongDate::parse(Some("2000")).unwrap(); assert_eq!(date.0, Some((2000, None))); + let date = SongDate::parse(Some("")).unwrap(); + assert_eq!(date.0, None); + assert!(SongDate::parse(Some("2000-31")).is_err()); assert!(SongDate::parse(Some("12-01")).is_err()); assert!(SongDate::parse(Some("invalid")).is_err());