Skip to content

Commit

Permalink
ID3v2: Properly handle solidus character (U+002F) in text frames
Browse files Browse the repository at this point in the history
V2 and V3 allow for the separation of multiple values with the solidus (/) character, while in V4 the separator is null (0). This was not accounted for previously, and would break valid V4 strings ("Foo / Bar" would be split into "Foo " and " Bar").

closes #82
  • Loading branch information
Serial-ATA committed Dec 12, 2022
1 parent e24585b commit d971615
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/id3/v2/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ impl From<ID3v2Tag> for Tag {
}),
) => {
let item_key = ItemKey::from_key(TagType::ID3v2, description);
for c in content.split(&['\0', '/'][..]) {
for c in content.split('\0') {
tag.items.push(TagItem::new(
item_key.clone(),
ItemValue::Text(c.to_string()),
Expand All @@ -547,7 +547,7 @@ impl From<ID3v2Tag> for Tag {
}),
) => {
let item_key = ItemKey::from_key(TagType::ID3v2, description);
for c in content.split(&['\0', '/'][..]) {
for c in content.split('\0') {
tag.items.push(TagItem::new(
item_key.clone(),
ItemValue::Locator(c.to_string()),
Expand All @@ -562,7 +562,7 @@ impl From<ID3v2Tag> for Tag {
| FrameValue::UnSyncText(LanguageFrame { content, .. })
| FrameValue::Text { value: content, .. }
| FrameValue::UserText(EncodedTextFrame { content, .. }) => {
for c in content.split(&['\0', '/'][..]) {
for c in content.split('\0') {
tag.items.push(TagItem::new(
item_key.clone(),
ItemValue::Text(c.to_string()),
Expand Down Expand Up @@ -603,7 +603,7 @@ impl From<Tag> for ID3v2Tag {
let mut s = String::with_capacity(iter.size_hint().0);
s.push_str(&first);
iter.for_each(|i| {
s.push('/');
s.push('\0');
s.push_str(&i);
});

Expand Down
Binary file added tests/files/assets/issue_82_solidus_in_tag.mp3
Binary file not shown.
13 changes: 13 additions & 0 deletions tests/files/mpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ fn read_with_junk_bytes_between_frames() {
assert_eq!(id3v1_tag.title(), Some("title test"));
}

#[test]
fn issue_82_solidus_in_tag() {
let file = Probe::open("tests/files/assets/issue_82_solidus_in_tag.mp3")
.unwrap()
.read()
.unwrap();

assert_eq!(file.file_type(), FileType::MPEG);

let id3v2_tag = &file.tags()[0];
assert_eq!(id3v2_tag.title(), Some("Foo / title"));
}

#[test]
fn write() {
let mut file = temp_file!("tests/files/assets/minimal/full_test.mp3");
Expand Down

0 comments on commit d971615

Please sign in to comment.