From bc5e56d3eb890081f4b31497e961ab1f8f404998 Mon Sep 17 00:00:00 2001 From: Urs Fleisch Date: Sat, 12 Nov 2022 11:36:22 +0100 Subject: [PATCH] Fix parsing of TXXX frame without description (#1069) --- .../id3v2/frames/textidentificationframe.cpp | 2 +- tests/test_id3v2.cpp | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp index f468b485..d40b683d 100644 --- a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp +++ b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp @@ -220,7 +220,7 @@ void TextIdentificationFrame::parseFields(const ByteVector &data) unsigned short firstBom = 0; for(ByteVectorList::ConstIterator it = l.begin(); it != l.end(); it++) { - if(!(*it).isEmpty()) { + if(!it->isEmpty() || (it == l.begin() && frameID() == "TXXX")) { if(d->textEncoding == String::Latin1) { d->fieldList.append(Tag::latin1StringHandler()->parse(*it)); } diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index b932a9a2..36ddc436 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -112,6 +112,8 @@ class TestID3v2 : public CppUnit::TestFixture CPPUNIT_TEST(testRenderPodcastFrame); CPPUNIT_TEST(testParsePrivateFrame); CPPUNIT_TEST(testRenderPrivateFrame); + CPPUNIT_TEST(testParseUserTextIdentificationFrame); + CPPUNIT_TEST(testRenderUserTextIdentificationFrame); CPPUNIT_TEST(testSaveUTF16Comment); CPPUNIT_TEST(testUpdateGenre23_1); CPPUNIT_TEST(testUpdateGenre23_2); @@ -841,6 +843,51 @@ public: f.render()); } + void testParseUserTextIdentificationFrame() + { + ID3v2::UserTextIdentificationFrame frameWithoutDescription( + ByteVector("TXXX" + "\x00\x00\x00\x06" + "\x00\x00\x00" + "\x00" + "Text", 16)); + CPPUNIT_ASSERT_EQUAL(String(""), frameWithoutDescription.description()); + CPPUNIT_ASSERT_EQUAL(String("Text"), frameWithoutDescription.fieldList()[1]); + + ID3v2::UserTextIdentificationFrame frameWithDescription( + ByteVector("TXXX" + "\x00\x00\x00\x11" + "\x00\x00\x00" + "Description\x00" + "Text", 27)); + CPPUNIT_ASSERT_EQUAL(String("Description"), frameWithDescription.description()); + CPPUNIT_ASSERT_EQUAL(String("Text"), frameWithDescription.fieldList()[1]); + } + + void testRenderUserTextIdentificationFrame() + { + ID3v2::UserTextIdentificationFrame f; + f.setDescription(""); + f.setText("Text"); + CPPUNIT_ASSERT_EQUAL( + ByteVector("TXXX" + "\x00\x00\x00\x06" + "\x00\x00\x00" + "\x00" + "Text", 16), + f.render()); + + f.setDescription("Description"); + f.setText("Text"); + CPPUNIT_ASSERT_EQUAL( + ByteVector("TXXX" + "\x00\x00\x00\x11" + "\x00\x00\x00" + "Description\x00" + "Text", 27), + f.render()); + } + void testItunes24FrameSize() { MPEG::File f(TEST_FILE_PATH_C("005411.id3"), false);