Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions lofty/src/ogg/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> =
Expand Down
54 changes: 54 additions & 0 deletions lofty/src/ogg/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}