diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-01-26 16:30:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-26 16:30:32 (GMT) |
commit | fd8aafd64d23e7de51566c7099c704d48da86eea (patch) | |
tree | 75640919672f0b3d44abee11e7c369e33d0174f4 /Lib/test | |
parent | 61f8f58f812dab2c201a9c64ebe69e3271a6663c (diff) | |
download | cpython-fd8aafd64d23e7de51566c7099c704d48da86eea.zip cpython-fd8aafd64d23e7de51566c7099c704d48da86eea.tar.gz cpython-fd8aafd64d23e7de51566c7099c704d48da86eea.tar.bz2 |
[3.12] gh-77749: Fix inconsistent behavior of non-ASCII handling in EmailPolicy.fold() (GH-6986) (GH-114606)
It now always encodes non-ASCII characters in headers if utf8 is false.
(cherry picked from commit 504334c7be5a56237df2598d338cd494a42fca4c)
Co-authored-by: Rito Takeuchi <licht-t@outlook.jp>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_email/test_policy.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_policy.py b/Lib/test/test_email/test_policy.py index e87c275..c6b9c80 100644 --- a/Lib/test/test_email/test_policy.py +++ b/Lib/test/test_email/test_policy.py @@ -135,6 +135,23 @@ class PolicyAPITests(unittest.TestCase): for attr, value in expected.items(): self.assertEqual(getattr(added, attr), value) + def test_fold_utf8(self): + expected_ascii = 'Subject: =?utf-8?q?=C3=A1?=\n' + expected_utf8 = 'Subject: á\n' + + msg = email.message.EmailMessage() + s = 'á' + msg['Subject'] = s + + p_ascii = email.policy.default.clone() + p_utf8 = email.policy.default.clone(utf8=True) + + self.assertEqual(p_ascii.fold('Subject', msg['Subject']), expected_ascii) + self.assertEqual(p_utf8.fold('Subject', msg['Subject']), expected_utf8) + + self.assertEqual(p_ascii.fold('Subject', s), expected_ascii) + self.assertEqual(p_utf8.fold('Subject', s), expected_utf8) + def test_fold_zero_max_line_length(self): expected = 'Subject: =?utf-8?q?=C3=A1?=\n' |