diff options
author | Vincent Richard <[email protected]> | 2015-02-16 17:43:03 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2015-02-16 17:43:03 +0000 |
commit | c5c66f9fdcd7d9ba4faf6f62cd17d1de112b228e (patch) | |
tree | e907e7f47670b1f66da4573d2432d0db3e768860 /tests/parser/textTest.cpp | |
parent | Issue #99: replaced C99 VLAs with dynamic array using std::vector. (diff) | |
download | vmime-c5c66f9fdcd7d9ba4faf6f62cd17d1de112b228e.tar.gz vmime-c5c66f9fdcd7d9ba4faf6f62cd17d1de112b228e.zip |
Issue #103: fix badly encoded words.
Diffstat (limited to 'tests/parser/textTest.cpp')
-rw-r--r-- | tests/parser/textTest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/parser/textTest.cpp b/tests/parser/textTest.cpp index 588dc194..978d9145 100644 --- a/tests/parser/textTest.cpp +++ b/tests/parser/textTest.cpp @@ -61,6 +61,7 @@ VMIME_TEST_SUITE_BEGIN(textTest) VMIME_TEST(testInternationalizedEmail_folding) VMIME_TEST(testWronglyPaddedB64Words) + VMIME_TEST(testFixBrokenWords) VMIME_TEST_LIST_END @@ -617,5 +618,50 @@ VMIME_TEST_SUITE_BEGIN(textTest) outText.getConvertedText(vmime::charset("utf-8"))); } + // Ensure that words which encode a non-integral number of characters + // are correctly decoded. + void testFixBrokenWords() + { + vmime::text outText; + + vmime::charsetConverterOptions opts; + opts.silentlyReplaceInvalidSequences = false; // just to be sure that broken words are actually fixed + + // Test case 1 + vmime::text::decodeAndUnfold + ("=?utf-8?Q?Gwena=C3?=" + "=?utf-8?Q?=ABl?=", &outText); + + VASSERT_EQ("1", "Gwena\xebl", + outText.getConvertedText(vmime::charset("iso-8859-1"), opts)); + + // Test case 2 + vmime::text::decodeAndUnfold + ("=?utf-8?B?5Lit6Yu85qmf5qKw6JGj5LqL5pyDMTAz5bm056ysMDXlsYbn?=" + "=?utf-8?B?rKwwN+asoeitsOeoiw==?=", &outText); + + VASSERT_EQ("2", "\xe4\xb8\xad\xe9\x8b\xbc\xe6\xa9\x9f\xe6\xa2\xb0" + "\xe8\x91\xa3\xe4\xba\x8b\xe6\x9c\x83\x31\x30\x33\xe5\xb9\xb4" + "\xe7\xac\xac\x30\x35\xe5\xb1\x86\xe7\xac\xac\x30\x37\xe6\xac" + "\xa1\xe8\xad\xb0\xe7\xa8\x8b", + outText.getConvertedText(vmime::charset("utf-8"))); + + // Test case 3 (a character spanning over 3 words: 'を' = E3 82 92) + vmime::text::decodeAndUnfold + ("=?utf-8?Q?abc=E3?=" + "=?utf-8?Q?=82?=" + "=?utf-8?Q?=92xyz?=", &outText); + + std::string out; // decode as UTF-16 then rencode to UTF-8 for easier comparison + vmime::charset::convert( + outText.getConvertedText(vmime::charset("utf-16"), opts), + out, + vmime::charset("utf-16"), + vmime::charset("utf-8") + ); + + VASSERT_EQ("3", "abc\xe3\x82\x92xyz", out); + } + VMIME_TEST_SUITE_END |