diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp index ed3d6db9..7f3d9023 100644 --- a/taglib/flac/flacfile.cpp +++ b/taglib/flac/flacfile.cpp @@ -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; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0e42ffce..005b7a5a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 index 00000000..93d9a8a1 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 index 00000000..acccc871 --- /dev/null +++ b/tests/test_flac.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include +#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);