]> granicus.if.org Git - taglib/commitdiff
Add a dummy byte to an empty ID3v2 frame to stick to the ID3v2 spec.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Sun, 22 Mar 2015 11:24:09 +0000 (20:24 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Sun, 22 Mar 2015 13:14:21 +0000 (22:14 +0900)
taglib/mpeg/id3v2/id3v2frame.cpp
tests/test_id3v2.cpp

index bee5375adfc90b8dceed9419944e02c3deb5f433..85e9f66da1e9be6abed5aa664e6f097174417ffb 100644 (file)
@@ -193,6 +193,9 @@ void Frame::setText(const String &)
 ByteVector Frame::render() const
 {
   ByteVector fieldData = renderFields();
+  if(fieldData.isEmpty())
+    fieldData = ByteVector("\x00", 1);
+
   d->header->setFrameSize(fieldData.size());
   ByteVector headerData = d->header->render();
 
index e0d2d1764d0f65517441007f6e8fe2f2b82a4620..c62be2808f35978d43cb78b4801e75a8499e6755 100644 (file)
@@ -92,6 +92,7 @@ class TestID3v2 : public CppUnit::TestFixture
   CPPUNIT_TEST(testParseTableOfContentsFrame);
   CPPUNIT_TEST(testRenderTableOfContentsFrame);
   CPPUNIT_TEST(testShrinkPadding);
+  CPPUNIT_TEST(testEmptyFrame);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -1039,6 +1040,35 @@ public:
     }
   }
 
+  void testEmptyFrame()
+  {
+    ScopedFileCopy copy("xing", ".mp3");
+    string newname = copy.fileName();
+
+    {
+      MPEG::File f(newname.c_str());
+      ID3v2::Tag *tag = f.ID3v2Tag(true);
+
+      ID3v2::UrlLinkFrame *frame1 = new ID3v2::UrlLinkFrame(
+        ByteVector("WOAF\x00\x00\x00\x01\x00\x00\x00", 11));
+      tag->addFrame(frame1);
+
+      ID3v2::TextIdentificationFrame *frame2 = new ID3v2::TextIdentificationFrame("TIT2");
+      frame2->setText("Title");
+      tag->addFrame(frame2);
+
+      f.save();
+    }
+
+    {
+      MPEG::File f(newname.c_str());
+      CPPUNIT_ASSERT_EQUAL(true, f.hasID3v2Tag());
+
+      ID3v2::Tag *tag = f.ID3v2Tag();
+      CPPUNIT_ASSERT_EQUAL(String("Title"), tag->title());
+    }
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v2);