Fixed a bug in creating String from ByteVector

This commit is contained in:
Tsuda Kageyu 2013-09-13 03:47:03 +09:00
parent c12b6697f9
commit cf892f2cb8
2 changed files with 20 additions and 2 deletions

View File

@ -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()));
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -1,7 +1,10 @@
#include <string>
#include <stdio.h>
#include <tstring.h>
#include <mpegfile.h>
#include <id3v1tag.h>
#include <cppunit/extensions/HelperMacros.h>
#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());
}
}
};