From b3cea6cca7ae2339d3207c9fb9e09dfeae9ad022 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Thu, 3 Sep 2015 09:12:05 +0900 Subject: [PATCH 1/5] Fix XiphComment::setComment() for the case that a Vorbis comment has the "COMMENT" field. --- taglib/ogg/xiphcomment.cpp | 9 ++++++++- tests/test_xiphcomment.cpp | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/taglib/ogg/xiphcomment.cpp b/taglib/ogg/xiphcomment.cpp index 9462607f..39903b04 100644 --- a/taglib/ogg/xiphcomment.cpp +++ b/taglib/ogg/xiphcomment.cpp @@ -137,7 +137,14 @@ void Ogg::XiphComment::setAlbum(const String &s) void Ogg::XiphComment::setComment(const String &s) { - addField(d->commentField.isEmpty() ? "DESCRIPTION" : d->commentField, s); + if(d->commentField.isEmpty()) { + if(!d->fieldListMap["DESCRIPTION"].isEmpty()) + d->commentField = "DESCRIPTION"; + else + d->commentField = "COMMENT"; + } + + addField(d->commentField, s); } void Ogg::XiphComment::setGenre(const String &s) diff --git a/tests/test_xiphcomment.cpp b/tests/test_xiphcomment.cpp index 6526229b..e2358333 100644 --- a/tests/test_xiphcomment.cpp +++ b/tests/test_xiphcomment.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -17,6 +18,7 @@ class TestXiphComment : public CppUnit::TestFixture CPPUNIT_TEST(testTrack); CPPUNIT_TEST(testSetTrack); CPPUNIT_TEST(testInvalidKeys); + CPPUNIT_TEST(testClearComment); CPPUNIT_TEST_SUITE_END(); public: @@ -74,6 +76,22 @@ public: CPPUNIT_ASSERT(cmt.properties().isEmpty()); } + void testClearComment() + { + ScopedFileCopy copy("no-tags", ".flac"); + + { + FLAC::File f(copy.fileName().c_str()); + f.xiphComment()->addField("COMMENT", "Comment1"); + f.save(); + } + { + FLAC::File f(copy.fileName().c_str()); + f.xiphComment()->setComment(""); + CPPUNIT_ASSERT_EQUAL(String(""), f.xiphComment()->comment()); + } + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestXiphComment); From ba5137bf2d3b1bcca9269e3a7f5f194243c87d23 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Thu, 12 Nov 2015 17:37:22 +0900 Subject: [PATCH 2/5] Use always "COMMENT" field when updating XiphComment. The recommended field name for additional comments is "COMMENT". It's the same behavior as "DATE" or "TRACKNUMBER" field. --- taglib/ogg/xiphcomment.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/taglib/ogg/xiphcomment.cpp b/taglib/ogg/xiphcomment.cpp index 39903b04..5630d25b 100644 --- a/taglib/ogg/xiphcomment.cpp +++ b/taglib/ogg/xiphcomment.cpp @@ -36,7 +36,6 @@ class Ogg::XiphComment::XiphCommentPrivate public: FieldListMap fieldListMap; String vendorID; - String commentField; }; //////////////////////////////////////////////////////////////////////////////// @@ -82,16 +81,10 @@ String Ogg::XiphComment::album() const String Ogg::XiphComment::comment() const { - if(!d->fieldListMap["DESCRIPTION"].isEmpty()) { - d->commentField = "DESCRIPTION"; - return d->fieldListMap["DESCRIPTION"].toString(); - } - - if(!d->fieldListMap["COMMENT"].isEmpty()) { - d->commentField = "COMMENT"; + if(!d->fieldListMap["COMMENT"].isEmpty()) return d->fieldListMap["COMMENT"].toString(); - } - + if(!d->fieldListMap["DESCRIPTION"].isEmpty()) + return d->fieldListMap["DESCRIPTION"].toString(); return String::null; } @@ -137,14 +130,8 @@ void Ogg::XiphComment::setAlbum(const String &s) void Ogg::XiphComment::setComment(const String &s) { - if(d->commentField.isEmpty()) { - if(!d->fieldListMap["DESCRIPTION"].isEmpty()) - d->commentField = "DESCRIPTION"; - else - d->commentField = "COMMENT"; - } - - addField(d->commentField, s); + removeField("DESCRIPTION"); + addField("COMMENT", s); } void Ogg::XiphComment::setGenre(const String &s) From 8f147034d6af7a4c2830b3113d4b257c1836fabe Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Fri, 13 Nov 2015 11:07:50 +0900 Subject: [PATCH 3/5] Add a test about handing "COMMENT" and "DESCIPRION" fields in XiphComment. --- tests/test_xiphcomment.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_xiphcomment.cpp b/tests/test_xiphcomment.cpp index e2358333..e21d9807 100644 --- a/tests/test_xiphcomment.cpp +++ b/tests/test_xiphcomment.cpp @@ -17,6 +17,7 @@ class TestXiphComment : public CppUnit::TestFixture CPPUNIT_TEST(testSetYear); CPPUNIT_TEST(testTrack); CPPUNIT_TEST(testSetTrack); + CPPUNIT_TEST(testSetComment); CPPUNIT_TEST(testInvalidKeys); CPPUNIT_TEST(testClearComment); CPPUNIT_TEST_SUITE_END(); @@ -63,6 +64,16 @@ public: CPPUNIT_ASSERT_EQUAL(String("3"), cmt.fieldListMap()["TRACKNUMBER"].front()); } + void testSetComment() + { + Ogg::XiphComment cmt; + cmt.addField("DESCRIPTION", "Test Comment 1"); + cmt.addField("COMMENT", "Test Comment 2"); + cmt.setComment("Test Comment 3"); + CPPUNIT_ASSERT(cmt.fieldListMap()["DESCRIPTION"].isEmpty()); + CPPUNIT_ASSERT_EQUAL(String("Test Comment 3"), cmt.fieldListMap()["COMMENT"].front()); + } + void testInvalidKeys() { PropertyMap map; From 7d0a651f3e1569f554d709c067798df1981c5c8f Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Fri, 20 Nov 2015 14:18:23 +0900 Subject: [PATCH 4/5] Revert "Use always "COMMENT" field when updating XiphComment." This reverts commit ba5137bf2d3b1bcca9269e3a7f5f194243c87d23. --- taglib/ogg/xiphcomment.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/taglib/ogg/xiphcomment.cpp b/taglib/ogg/xiphcomment.cpp index 5630d25b..39903b04 100644 --- a/taglib/ogg/xiphcomment.cpp +++ b/taglib/ogg/xiphcomment.cpp @@ -36,6 +36,7 @@ class Ogg::XiphComment::XiphCommentPrivate public: FieldListMap fieldListMap; String vendorID; + String commentField; }; //////////////////////////////////////////////////////////////////////////////// @@ -81,10 +82,16 @@ String Ogg::XiphComment::album() const String Ogg::XiphComment::comment() const { - if(!d->fieldListMap["COMMENT"].isEmpty()) - return d->fieldListMap["COMMENT"].toString(); - if(!d->fieldListMap["DESCRIPTION"].isEmpty()) + if(!d->fieldListMap["DESCRIPTION"].isEmpty()) { + d->commentField = "DESCRIPTION"; return d->fieldListMap["DESCRIPTION"].toString(); + } + + if(!d->fieldListMap["COMMENT"].isEmpty()) { + d->commentField = "COMMENT"; + return d->fieldListMap["COMMENT"].toString(); + } + return String::null; } @@ -130,8 +137,14 @@ void Ogg::XiphComment::setAlbum(const String &s) void Ogg::XiphComment::setComment(const String &s) { - removeField("DESCRIPTION"); - addField("COMMENT", s); + if(d->commentField.isEmpty()) { + if(!d->fieldListMap["DESCRIPTION"].isEmpty()) + d->commentField = "DESCRIPTION"; + else + d->commentField = "COMMENT"; + } + + addField(d->commentField, s); } void Ogg::XiphComment::setGenre(const String &s) From 29b0568decccf28ac53571be7d48ac8a0cf4a747 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Fri, 20 Nov 2015 14:18:40 +0900 Subject: [PATCH 5/5] Revert "Add a test about handing "COMMENT" and "DESCIPRION" fields in XiphComment." This reverts commit 8f147034d6af7a4c2830b3113d4b257c1836fabe. --- tests/test_xiphcomment.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/test_xiphcomment.cpp b/tests/test_xiphcomment.cpp index e21d9807..e2358333 100644 --- a/tests/test_xiphcomment.cpp +++ b/tests/test_xiphcomment.cpp @@ -17,7 +17,6 @@ class TestXiphComment : public CppUnit::TestFixture CPPUNIT_TEST(testSetYear); CPPUNIT_TEST(testTrack); CPPUNIT_TEST(testSetTrack); - CPPUNIT_TEST(testSetComment); CPPUNIT_TEST(testInvalidKeys); CPPUNIT_TEST(testClearComment); CPPUNIT_TEST_SUITE_END(); @@ -64,16 +63,6 @@ public: CPPUNIT_ASSERT_EQUAL(String("3"), cmt.fieldListMap()["TRACKNUMBER"].front()); } - void testSetComment() - { - Ogg::XiphComment cmt; - cmt.addField("DESCRIPTION", "Test Comment 1"); - cmt.addField("COMMENT", "Test Comment 2"); - cmt.setComment("Test Comment 3"); - CPPUNIT_ASSERT(cmt.fieldListMap()["DESCRIPTION"].isEmpty()); - CPPUNIT_ASSERT_EQUAL(String("Test Comment 3"), cmt.fieldListMap()["COMMENT"].front()); - } - void testInvalidKeys() { PropertyMap map;