From cf892f2cb8c578eaed9cbb08a4e981681a69e398 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Fri, 13 Sep 2013 03:47:03 +0900 Subject: [PATCH] Fixed a bug in creating String from ByteVector --- taglib/toolkit/tstring.cpp | 3 +++ tests/test_id3v1.cpp | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 56840f48..75a9833e 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -268,6 +268,9 @@ String::String(const ByteVector &v, Type t) copyFromUTF8(v.data(), v.size()); else copyFromUTF16(v.data(), v.size(), t); + + // If we hit a null in the ByteVector, shrink the string again. + d->data.resize(::wcslen(d->data.c_str())); } //////////////////////////////////////////////////////////////////////////////// diff --git a/tests/test_id3v1.cpp b/tests/test_id3v1.cpp index 1d0a4974..7db2dbbf 100644 --- a/tests/test_id3v1.cpp +++ b/tests/test_id3v1.cpp @@ -1,7 +1,10 @@ #include #include +#include +#include #include #include +#include "utils.h" using namespace std; using namespace TagLib; @@ -16,8 +19,20 @@ public: void testStripWhiteSpace() { - ID3v1::StringHandler h; - CPPUNIT_ASSERT_EQUAL(String("Foo"), h.parse(ByteVector("Foo "))); + ScopedFileCopy copy("xing", ".mp3"); + string newname = copy.fileName(); + + { + MPEG::File f(newname.c_str()); + f.ID3v1Tag(true)->setArtist("Artist "); + f.save(); + } + + { + MPEG::File f(newname.c_str()); + CPPUNIT_ASSERT(f.ID3v1Tag(false)); + CPPUNIT_ASSERT_EQUAL(String("Artist"), f.ID3v1Tag(false)->artist()); + } } }; -- 2.40.0