From 7b8d576bdee3b7304806b3008bfde30baa3d03a6 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Thu, 10 Nov 2016 17:09:40 +0900 Subject: [PATCH] Don't decode redundant UTF-8 sequences in Win32. Linux and OS X are working well and won't be affected. --- taglib/toolkit/tstring.cpp | 2 +- tests/test_string.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index a1891a45..44788249 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -88,7 +88,7 @@ namespace #ifdef _WIN32 len = ::MultiByteToWideChar( - CP_UTF8, 0, src, static_cast(srcLength), dst, static_cast(dstLength)); + CP_UTF8, MB_ERR_INVALID_CHARS, src, static_cast(srcLength), dst, static_cast(dstLength)); #else diff --git a/tests/test_string.cpp b/tests/test_string.cpp index f9f1a2dd..599e002d 100644 --- a/tests/test_string.cpp +++ b/tests/test_string.cpp @@ -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); -- 2.40.0