From: Lukáš Lalinský Date: Sat, 19 Mar 2011 06:37:28 +0000 (+0100) Subject: Don't overwrite fields that already exist X-Git-Tag: v1.8beta~138 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=71e224fed812a0ab4448c5b9c2ab801a3c3a9f27;p=taglib Don't overwrite fields that already exist We can have multiple fields in the Vorbis Comment (e.g. two artist names), but TagUnion only takes the first one, so it will effectively strip the extra fields. https://bugs.kde.org/show_bug.cgi?id=268854 --- diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp index c8cc1fb8..f882ae7b 100644 --- a/taglib/flac/flacfile.cpp +++ b/taglib/flac/flacfile.cpp @@ -149,7 +149,7 @@ bool FLAC::File::save() // Create new vorbis comments - Tag::duplicate(&d->tag, xiphComment(true), true); + Tag::duplicate(&d->tag, xiphComment(true), false); d->xiphCommentData = xiphComment()->render(false); diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp index ba3d99da..4b54a7ca 100644 --- a/tests/test_flac.cpp +++ b/tests/test_flac.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "utils.h" using namespace std; @@ -20,6 +21,7 @@ class TestFLAC : public CppUnit::TestFixture CPPUNIT_TEST(testReplacePicture); CPPUNIT_TEST(testRemoveAllPictures); CPPUNIT_TEST(testRepeatedSave); + CPPUNIT_TEST(testSaveMultipleValues); CPPUNIT_TEST_SUITE_END(); public: @@ -186,6 +188,26 @@ public: CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), tag->title()); } + void testSaveMultipleValues() + { + ScopedFileCopy copy("silence-44-s", ".flac", false); + string newname = copy.fileName(); + + FLAC::File *f = new FLAC::File(newname.c_str()); + Ogg::XiphComment* c = f->xiphComment(true); + c->addField("ARTIST", "artist 1", true); + c->addField("ARTIST", "artist 2", false); + f->save(); + delete f; + + f = new FLAC::File(newname.c_str()); + c = f->xiphComment(true); + Ogg::FieldListMap m = c->fieldListMap(); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), m["ARTIST"].size()); + CPPUNIT_ASSERT_EQUAL(String("artist 1"), m["ARTIST"][0]); + CPPUNIT_ASSERT_EQUAL(String("artist 2"), m["ARTIST"][1]); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);