8000 gh-77749: Fix inconsistent behavior of non-ascii handling in EmailPolicy.fold by Licht-T · Pull Request #6986 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-77749: Fix inconsistent behavior of non-ascii handling in EmailPolicy.fold #6986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Diff view
Diff view
Prev Previous commit
Next Next commit
TST: Add test for non-ascii handling in EmailPolicy.fold
  • Loading branch information
Licht-T committed May 19, 2018
commit 09c0f097a0cb2aef982e7c20fb382309dbb0752b
29 changes: 29 additions & 0 deletions Lib/test/test_email/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,35 @@ def test_policy_addition(self):
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_register_defect(self):
class Dummy:
def __init__(self):
Expand Down
0