diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c3793e1a..5dfdbdd8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **ID3v2**: Support parsing UTF-16 `COMM`/`USLT` frames with a single BOM ([issue](https://github.com/Serial-ATA/lofty-rs/issues/532)) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/535)) - Some encoders will only write a BOM to the frame's description, rather than to every string in the frame. This was previously only supported in `SYLT` frames, and has been extended to `COMM` and `USLT`. +- **Vorbis Comments**: Parse `TRACKNUMBER` with respect to `ParseOptions::implicit_conversions` ([issue](https://github.com/Serial-ATA/lofty-rs/issues/540)) ([PR](https://github.com/Serial-ATA/lofty-rs/issues/542)) ### Removed diff --git a/lofty/src/ogg/read.rs b/lofty/src/ogg/read.rs index 8b4ec010c..684875819 100644 --- a/lofty/src/ogg/read.rs +++ b/lofty/src/ogg/read.rs @@ -172,6 +172,12 @@ where k if k.eq_ignore_ascii_case(b"TRACKNUMBER") => { match utf8_decode_str(value) { Ok(value) => { + if !parse_options.implicit_conversions { + tag.items + .push((String::from("TRACKNUMBER"), value.to_owned())); + continue; + } + // try to parse as current/total let mut value_split = value.splitn(2, '/'); let track_number: Option = diff --git a/lofty/src/ogg/tag.rs b/lofty/src/ogg/tag.rs index 396dc72ea..e56a2fff7 100644 --- a/lofty/src/ogg/tag.rs +++ b/lofty/src/ogg/tag.rs @@ -923,4 +923,58 @@ mod tests { assert_eq!(tag.pictures().len(), 0); // Artist, no picture assert!(tag.artist().is_some()); } + + // case TRACKNUMBER=01/05 disable implicit_conversions + #[test_log::test] + fn issue_540_disable_implicit_conversions() { + let mut comments = VorbisComments::new(); + comments.insert(String::from("TRACKNUMBER"), String::from("01/05")); + + let mut comments_bytes = Vec::new(); + comments + .dump_to(&mut comments_bytes, WriteOptions::default()) + .unwrap(); + + let mut reader = Cursor::new(&comments_bytes); + let tag = crate::ogg::read::read_comments( + &mut reader, + comments_bytes.len() as u64, + ParseOptions::new() + .parsing_mode(ParsingMode::Strict) + .implicit_conversions(false) + .read_cover_art(false), + ) + .unwrap(); + + assert_eq!(tag.track(), None); + assert_eq!(tag.track_total(), None); + assert_eq!(tag.get("TRACKNUMBER"), Some("01/05")); + } + + // case track number and total with leading 0 + #[test_log::test] + fn opus_issue_540_leading_0() { + let mut comments = VorbisComments::new(); + comments.insert(String::from("TRACKNUMBER"), String::from("01")); + comments.insert(String::from("TRACKTOTAL"), String::from("05")); + + let mut comments_bytes = Vec::new(); + comments + .dump_to(&mut comments_bytes, WriteOptions::default()) + .unwrap(); + + let mut reader = Cursor::new(&comments_bytes); + let tag = crate::ogg::read::read_comments( + &mut reader, + comments_bytes.len() as u64, + ParseOptions::new() + .parsing_mode(ParsingMode::Strict) + .implicit_conversions(false) + .read_cover_art(false), + ) + .unwrap(); + + assert_eq!(tag.get("TRACKNUMBER"), Some("01")); + assert_eq!(tag.get("TRACKTOTAL"), Some("05")); + } }