]> granicus.if.org Git - taglib/commitdiff
Fixed a bug in creating String from ByteVector
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Thu, 12 Sep 2013 18:47:03 +0000 (03:47 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Thu, 12 Sep 2013 18:47:03 +0000 (03:47 +0900)
taglib/toolkit/tstring.cpp
tests/test_id3v1.cpp

index 56840f48840446c86ef4a2af49ba6890f37d79e8..75a9833eff5a8c8bbdaba136ef16ea258df41b88 100644 (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()));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
index 1d0a4974ad25bb7b1793a1cd4df09ac4afe90c24..7db2dbbf5aea08bf7b85b132e29bb84bde3095a0 100644 (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());
+    }
   }
 
 };