Skip to content

Commit d9b7323

Browse files
Methapon2001Serial-ATA
authored andcommitted
fix: don't overwrite track/track_total if disable implicit conversion
1 parent 09a9352 commit d9b7323

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

lofty/src/ogg/read.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ where
172172
k if k.eq_ignore_ascii_case(b"TRACKNUMBER") => {
173173
match utf8_decode_str(value) {
174174
Ok(value) => {
175+
if !parse_options.implicit_conversions {
176+
tag.items
177+
.push((String::from("TRACKNUMBER"), value.to_owned()));
178+
continue;
179+
}
180+
175181
// try to parse as current/total
176182
let mut value_split = value.splitn(2, '/');
177183
let track_number: Option<u32> =
226 Bytes
Binary file not shown.
Binary file not shown.

lofty/tests/files/ogg.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,41 @@ fn opus_issue_499() {
181181
assert_eq!(comments.track_total(), Some(22));
182182
}
183183

184+
// case TRACKNUMBER=01/05 disable implicit_conversions
185+
#[test_log::test]
186+
fn opus_issue_540_disable_implicit_conversions() {
187+
use lofty::ogg::OpusFile;
188+
189+
let file = std::fs::read("tests/files/assets/issue_540.opus").unwrap();
190+
let opus_file = OpusFile::read_from(
191+
&mut std::io::Cursor::new(file),
192+
ParseOptions::new().implicit_conversions(false),
193+
)
194+
.unwrap();
195+
196+
let comments = opus_file.vorbis_comments();
197+
assert_eq!(comments.track(), None);
198+
assert_eq!(comments.track_total(), None);
199+
assert_eq!(comments.get("TRACKNUMBER"), Some("01/05"));
200+
}
201+
202+
// case track number and total with leading 0
203+
#[test_log::test]
204+
fn opus_issue_540_leading_0() {
205+
use lofty::ogg::OpusFile;
206+
207+
let file = std::fs::read("tests/files/assets/issue_540_leading_0.opus").unwrap();
208+
let opus_file = OpusFile::read_from(
209+
&mut std::io::Cursor::new(file),
210+
ParseOptions::new().implicit_conversions(false),
211+
)
212+
.unwrap();
213+
214+
let comments = opus_file.vorbis_comments();
215+
assert_eq!(comments.get("TRACKNUMBER"), Some("01"));
216+
assert_eq!(comments.get("TRACKTOTAL"), Some("05"));
217+
}
218+
184219
// case TRACKNUMBER=a5 (vinyl format)
185220
#[test_log::test]
186221
fn opus_issue_499_vinyl_track_number() {

0 commit comments

Comments
 (0)