]> granicus.if.org Git - taglib/commitdiff
Always read tags from the first Vorbis Comment block in FLAC files
authorLukáš Lalinský <lalinsky@gmail.com>
Mon, 2 Nov 2009 19:41:12 +0000 (19:41 +0000)
committerLukáš Lalinský <lalinsky@gmail.com>
Mon, 2 Nov 2009 19:41:12 +0000 (19:41 +0000)
Prevously TagLib saved tags to the first block, but read them from the
last one. Having multiple VC blocks is a non-standard situation, but
this is the best we can do (libFLAC also uses the first block in the
case of multiple VC blocks).

BUG:211089

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1043985 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

taglib/flac/flacfile.cpp
tests/CMakeLists.txt
tests/data/multiple-vc.flac [new file with mode: 0644]
tests/test_flac.cpp [new file with mode: 0644]

index ed3d6db91e39350623fe60d9b1486332c934b54d..7f3d9023ab2a0ae5e78a133204643ec949e07677 100644 (file)
@@ -406,7 +406,6 @@ void FLAC::File::scan()
   nextBlockOffset += length + 4;
 
   // Search through the remaining metadata
-
   while(!isLastBlock) {
 
     header = readBlock(4);
@@ -416,8 +415,13 @@ void FLAC::File::scan()
 
     // Found the vorbis-comment
     if(blockType == VorbisComment) {
-      d->xiphCommentData = readBlock(length);
-      d->hasXiphComment = true;
+      if(!d->hasXiphComment) {
+        d->xiphCommentData = readBlock(length);
+        d->hasXiphComment = true;
+      }
+      else {
+        debug("FLAC::File::scan() -- multiple Vorbis Comment blocks found, using the first one");
+      }
     }
 
     nextBlockOffset += length + 4;
index 0e42ffce10a0a8b61e3156616fdb9e39456b24c8..005b7a5a0c38ed5bb7d0c1f6771a6a038e38b510 100644 (file)
@@ -36,6 +36,7 @@ SET(test_runner_SRCS
   test_riff.cpp
   test_ogg.cpp
   test_oggflac.cpp
+  test_flac.cpp
 )
 IF(WITH_MP4)
    SET(test_runner_SRCS ${test_runner_SRCS}
diff --git a/tests/data/multiple-vc.flac b/tests/data/multiple-vc.flac
new file mode 100644 (file)
index 0000000..93d9a8a
Binary files /dev/null and b/tests/data/multiple-vc.flac differ
diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp
new file mode 100644 (file)
index 0000000..acccc87
--- /dev/null
@@ -0,0 +1,40 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <string>
+#include <stdio.h>
+#include <tag.h>
+#include <tstringlist.h>
+#include <tbytevectorlist.h>
+#include <flacfile.h>
+#include "utils.h"
+
+using namespace std;
+using namespace TagLib;
+
+class TestFLAC : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE(TestFLAC);
+  CPPUNIT_TEST(testMultipleCommentBlocks);
+  CPPUNIT_TEST_SUITE_END();
+
+public:
+
+  void testMultipleCommentBlocks()
+  {
+    string newname = copyFile("multiple-vc", ".flac");
+
+    FLAC::File *f = new FLAC::File(newname.c_str());
+    CPPUNIT_ASSERT_EQUAL(String("Artist 1"), f->tag()->artist());
+    f->tag()->setArtist("The Artist");
+    f->save();
+    delete f;
+
+    f = new FLAC::File(newname.c_str());
+    CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist());
+    delete f;
+
+    deleteFile(newname);
+  }
+
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);