Skip to content

Commit

Permalink
fix(song/parse): fix date input have less than 4 chars (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
vnghia authored May 2, 2024
1 parent 102c53c commit 6938e30
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils/song/parse/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 6938e30

Please sign in to comment.