Skip to content

Commit

Permalink
ID3v2 : Strip BOMs from ID3v.2.2 values [#241]
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeugma440 committed Jan 3, 2024
1 parent feebd63 commit b9ad834
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions ATL.unit-test/IO/MetaData/ID3v2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ public void TagIO_R_ID3v22_UTF16()
Assert.IsTrue(theFile.ID3v2.Exists);

// Supported fields
Assert.AreEqual("bébé", theFile.ID3v2.Title);
Assert.AreEqual("bébé", theFile.ID3v2.Title);
Assert.AreEqual("ALBUM!", theFile.ID3v2.Album);
Assert.AreEqual("", theFile.ID3v2.Artist);
Assert.AreEqual("", theFile.ID3v2.Artist);
Assert.AreEqual("ALBUMARTIST", theFile.ID3v2.AlbumArtist);
Assert.AreEqual("I have no IDE and i must code bébé 父", theFile.ID3v2.Comment);
Assert.AreEqual("I have no IDE and i must code bébé 父", theFile.ID3v2.Comment);
Assert.AreEqual(1997, theFile.ID3v2.Date.Year);
Assert.AreEqual("House", theFile.ID3v2.Genre);
Assert.AreEqual(1, theFile.ID3v2.TrackNumber);
Expand Down
19 changes: 10 additions & 9 deletions ATL/AudioData/IO/ID3v2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ Frame size encoding conventions

if (Frame.ID.StartsWith("COM"))
{
if (null == comments) comments = new List<MetaFieldInfo>();
comments ??= new List<MetaFieldInfo>();
comment = new MetaFieldInfo(getImplementedTagType(), "")
{
Language = structure.LanguageCode,
Expand All @@ -736,7 +736,7 @@ Frame size encoding conventions
}
else if (Frame.ID.StartsWith("USL") || Frame.ID.StartsWith("ULT"))
{
if (null == tagData.Lyrics) tagData.Lyrics = new LyricsInfo();
tagData.Lyrics ??= new LyricsInfo();
tagData.Lyrics.LanguageCode = structure.LanguageCode;
tagData.Lyrics.Description = structure.ContentDescriptor;
inLyrics = true;
Expand All @@ -747,7 +747,7 @@ Frame size encoding conventions
else if (Frame.ID.StartsWith("SYL")) // Synch'ed lyrics
{
RichStructure structure = readSynchedLyricsStructure(source, m_tagVersion, encodingCode, frameEncoding);
if (null == tagData.Lyrics) tagData.Lyrics = new LyricsInfo();
tagData.Lyrics ??= new LyricsInfo();
tagData.Lyrics.LanguageCode = structure.LanguageCode;
tagData.Lyrics.Description = structure.ContentDescriptor;
tagData.Lyrics.ContentType = (LyricsInfo.LyricsType)structure.ContentType;
Expand All @@ -756,11 +756,11 @@ Frame size encoding conventions
dataSize -= structure.Size;
}

// A $01 "Unicode" encoding flag means the presence of a BOM (Byte Order Mark) if version > 2.2
if (m_tagVersion > TAG_VERSION_2_2 && (1 == encodingCode))
// A $01 "Unicode" encoding flag means the presence of a BOM (Byte Order Mark)
// NB : Even if it's not part of the spec, BOMs may appear on ID3v2.2 tags
if (1 == encodingCode)
{
BomProperties bom = readBOM(source);

if (bom.Found)
{
frameEncoding = bom.Encoding;
Expand Down Expand Up @@ -842,7 +842,7 @@ Frame size encoding conventions
}
else if (Frame.ID.StartsWith("CHA")) // Chapters
{
if (null == tagData.Chapters) tagData.Chapters = new List<ChapterInfo>();
tagData.Chapters ??= new List<ChapterInfo>();
chapter = new ChapterInfo();
tagData.Chapters.Add(chapter);

Expand Down Expand Up @@ -1013,7 +1013,7 @@ Frame size encoding conventions
}
else
{
tagData.Chapters[tagData.Chapters.Count - 1].Picture = picInfo;
tagData.Chapters[^1].Picture = picInfo;
}
}
} // Picture frame
Expand Down Expand Up @@ -1152,7 +1152,8 @@ internal int writeInternal(TagData tag, BinaryWriter w)
/// <returns>True if writing operation succeeded; false if not</returns>
protected override int write(TagData tag, Stream s, string zone)
{
using (BinaryWriter w = new BinaryWriter(s, Encoding.UTF8, true)) return write(tag, w);
using BinaryWriter w = new BinaryWriter(s, Encoding.UTF8, true);
return write(tag, w);
}

private int write(TagData tag, BinaryWriter w)
Expand Down

0 comments on commit b9ad834

Please sign in to comment.