8000 [3.11] gh-100884: email/_header_value_parser: don't encode list separ… · python/cpython@70754d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 70754d2

Browse files
[3.11] gh-100884: email/_header_value_parser: don't encode list separators (GH-100885) (GH-115593)
ListSeparator should not be encoded. This could happen when a long line pushes its separator to the next line, which would have been encoded. (cherry picked from commit 09fab93) Co-authored-by: Thomas Weißschuh <thomas@t-8ch.de>
1 parent bc11905 commit 70754d2

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Lib/email/_header_value_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ class _InvalidEwError(errors.HeaderParseError):
949949
# up other parse trees. Maybe should have tests for that, too.
950950
DOT = ValueTerminal('.', 'dot')
951951
ListSeparator = ValueTerminal(',', 'list-separator')
952+
ListSeparator.as_ew_allowed = False
952953
RouteComponentMarker = ValueTerminal('@', 'route-component-marker')
953954

954955
#
@@ -2022,7 +2023,7 @@ def get_address_list(value):
20222023
address_list.defects.append(errors.InvalidHeaderDefect(
20232024
"invalid address in address-list"))
20242025
if value: # Must be a , at this point.
2025-
address_list.append(ValueTerminal(',', 'list-separator'))
2026+
address_list.append(ListSeparator)
20262027
value = value[1:]
20272028
return address_list, value
20282029

Lib/test/test_email/test__header_value_parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,6 +2985,11 @@ def test_address_list_with_unicode_names_in_quotes(self):
29852985
'=?utf-8?q?H=C3=BCbsch?= Kaktus <beautiful@example.com>,\n'
29862986
' =?utf-8?q?bei=C3=9Ft_bei=C3=9Ft?= <biter@example.com>\n')
29872987

2988+
def test_address_list_with_list_separator_after_fold(self):
2989+
to = '0123456789' * 8 + '@foo, ä <foo@bar>'
2990+
self._test(parser.get_address_list(to)[0],
2991+
'0123456789' * 8 + '@foo,\n =?utf-8?q?=C3=A4?= <foo@bar>\n')
2992+
29882993
# XXX Need tests with comments on various sides of a unicode token,
29892994
# and with unicode tokens in the comments. Spaces inside the quotes
29902995
# currently don't do the right thing.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
email: fix misfolding of comma in address-lists over multiple lines in
2+
combination with unicode encoding.

0 commit comments

Comments
 (0)
0