aboutsummaryrefslogtreecommitdiffstats
path: root/tests/parser/wordEncoderTest.cpp
diff options
context:
space:
mode:
authorJan Engelhardt <[email protected]>2024-05-21 13:47:05 +0000
committerGitHub <[email protected]>2024-05-21 13:47:05 +0000
commitb447adbe373d3940d2023d8e7a6ec21c7bfb8a48 (patch)
tree5c8092e7215d83400ec5ad3a377f3da9db7678c0 /tests/parser/wordEncoderTest.cpp
parentvmime: avoid changing SEVEN_BIT when encoding::decideImpl sees U+007F (#303) (diff)
downloadvmime-b447adbe373d3940d2023d8e7a6ec21c7bfb8a48.tar.gz
vmime-b447adbe373d3940d2023d8e7a6ec21c7bfb8a48.zip
Fixes/comments for guessBestEncoding (#304)
* tests: add case for getRecommendedEncoding * vmime: avoid integer multiply wraparound in wordEncoder::guessBestEncoding If the input string is 42949673 characters long or larger, there will be integer overflow on 32-bit platforms when multiplying by 100. Switch that one computation to floating point. * vmime: update comment in wordEncoder::guessBestEncoding
Diffstat (limited to 'tests/parser/wordEncoderTest.cpp')
-rw-r--r--tests/parser/wordEncoderTest.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/parser/wordEncoderTest.cpp b/tests/parser/wordEncoderTest.cpp
index 08d34aa4..0c827bff 100644
--- a/tests/parser/wordEncoderTest.cpp
+++ b/tests/parser/wordEncoderTest.cpp
@@ -36,6 +36,7 @@ VMIME_TEST_SUITE_BEGIN(wordEncoderTest)
VMIME_TEST(testIsEncodingNeeded_specialChars)
VMIME_TEST(testGuessBestEncoding_QP)
VMIME_TEST(testGuessBestEncoding_B64)
+ VMIME_TEST(testGuessBestEncoding_size)
VMIME_TEST(testEncodeQP_RFC2047)
VMIME_TEST_LIST_END
@@ -159,6 +160,14 @@ VMIME_TEST_SUITE_BEGIN(wordEncoderTest)
);
}
+ void testGuessBestEncoding_size() {
+
+ std::string i(42949673, 'a');
+ auto enc = vmime::wordEncoder::guessBestEncoding(i, vmime::charset("utf-8"));
+ VASSERT_EQ("1", enc, vmime::wordEncoder::ENCODING_QP);
+
+ }
+
void testEncodeQP_RFC2047() {
// When Quoted-Printable is used, it should be RFC-2047 QP encoding