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);