8000 gh-121650: Encode newlines in headers, and verify headers are sound by encukou · Pull Request #122233 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-121650: Encode newlines in headers, and verify headers are sound #122233

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
merged 12 commits into from
Jul 30, 2024
Merged
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
  • Loading branch information
encukou and serhiy-storchaka authored Jul 30, 2024
commit 596a25b66e10b821148d99098e427ed5734298e0
8 changes: 4 additions & 4 deletions Lib/email/_header_value_parser.py
< C5DE /tr>
Original file line number Diff line number Diff line change
Expand Up @@ -2804,12 +2804,12 @@ def _refold_parse_tree(parse_tree, *, policy):
wrap_as_ew_blocked -= 1
continue
tstr = str(part)
if part.token_type == 'ptext' and set(tstr) & SPECIALSNL:
if part.token_type == 'ptext'
# Encode if tstr contains special characters.
want_encoding = True
elif set(tstr) & NLSET:
want_encoding = not SPECIALSNL.isdisjoint(tstr)
else:
# Encode if text contains newlines
want_encoding = True
want_encoding = not NLSET.isdisjoint(tstr)
try:
tstr.encode(encoding)
charset = encoding
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_email/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ def fold(self, **kwargs):
del message['Header']
message['Header'] = LiteralHeader(text)

expected = text#.replace('\r\n', '\n')
self.assertEqual(
message.as_string(),
f"{text}\nBody",
Expand Down
Loading
0