Always read tags from the first Vorbis Comment block in FLAC files

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
This commit is contained in:
Lukáš Lalinský 2009-11-02 19:41:12 +00:00
parent 2039c725f4
commit c962d78a57
4 changed files with 48 additions and 3 deletions

View 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;

View 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}

BIN
tests/data/multiple-vc.flac Normal file

Binary file not shown.

40
tests/test_flac.cpp Normal file
View File

@ -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);