]> granicus.if.org Git - taglib/commitdiff
Don't decode redundant UTF-8 sequences in Win32.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Thu, 10 Nov 2016 08:09:40 +0000 (17:09 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Thu, 10 Nov 2016 08:12:58 +0000 (17:12 +0900)
Linux and OS X are working well and won't be affected.

taglib/toolkit/tstring.cpp
tests/test_string.cpp

index a1891a45699cacb2efbca7b6920ced145ab22b7c..44788249e99cbdcf50ec1461996bcff3e22e65e2 100644 (file)
@@ -88,7 +88,7 @@ namespace
 #ifdef _WIN32
 
     len = ::MultiByteToWideChar(
-      CP_UTF8, 0, src, static_cast<int>(srcLength), dst, static_cast<int>(dstLength));
+      CP_UTF8, MB_ERR_INVALID_CHARS, src, static_cast<int>(srcLength), dst, static_cast<int>(dstLength));
 
 #else
 
index f9f1a2dd8fb56a7a28e8e309ad91b1f5cbcb099b..599e002dadcbf732e809939fd85e4668d1e33932 100644 (file)
@@ -50,6 +50,7 @@ class TestString : public CppUnit::TestFixture
   CPPUNIT_TEST(testEncodeNonLatin1);
   CPPUNIT_TEST(testEncodeEmpty);
   CPPUNIT_TEST(testIterator);
+  CPPUNIT_TEST(testRedundantUTF8);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -321,6 +322,14 @@ public:
     CPPUNIT_ASSERT_EQUAL(L'I', *it2);
   }
 
+  void testRedundantUTF8()
+  {
+    CPPUNIT_ASSERT_EQUAL(String("/"), String(ByteVector("\x2F"), String::UTF8));
+    CPPUNIT_ASSERT(String(ByteVector("\xC0\xAF"), String::UTF8).isEmpty());
+    CPPUNIT_ASSERT(String(ByteVector("\xE0\x80\xAF"), String::UTF8).isEmpty());
+    CPPUNIT_ASSERT(String(ByteVector("\xF0\x80\x80\xAF"), String::UTF8).isEmpty());
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestString);