]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-100884: email/_header_value_parser: don't encode list separators (GH-100885...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 17 Feb 2024 13:00:39 +0000 (14:00 +0100)
committerGitHub <noreply@github.com>
Sat, 17 Feb 2024 13:00:39 +0000 (15:00 +0200)
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 09fab93c3d857496c0bd162797fab816c311ee48)

Co-authored-by: Thomas Weißschuh <thomas@t-8ch.de>
Lib/email/_header_value_parser.py
Lib/test/test_email/test__header_value_parser.py
Misc/NEWS.d/next/Library/2023-01-09-14-08-02.gh-issue-100884.DcmdLl.rst [new file with mode: 0644]

index 5b653f66c18554cbc52a1f17d5c3342acf58dc8e..e4a342d446f6a38418a7247d65faa7af96f88da6 100644 (file)
@@ -949,6 +949,7 @@ class _InvalidEwError(errors.HeaderParseError):
 # up other parse trees.  Maybe should have  tests for that, too.
 DOT = ValueTerminal('.', 'dot')
 ListSeparator = ValueTerminal(',', 'list-separator')
+ListSeparator.as_ew_allowed = False
 RouteComponentMarker = ValueTerminal('@', 'route-component-marker')
 
 #
@@ -2022,7 +2023,7 @@ def get_address_list(value):
             address_list.defects.append(errors.InvalidHeaderDefect(
                 "invalid address in address-list"))
         if value:  # Must be a , at this point.
-            address_list.append(ValueTerminal(',', 'list-separator'))
+            address_list.append(ListSeparator)
             value = value[1:]
     return address_list, value
 
index bdb0e55f21069f7596acab664f63c7ddd604b362..f7e80749c456f8fdc92ce56aa2645c54e1b680e7 100644 (file)
@@ -2985,6 +2985,11 @@ class TestFolding(TestEmailBase):
             '=?utf-8?q?H=C3=BCbsch?= Kaktus <beautiful@example.com>,\n'
                 ' =?utf-8?q?bei=C3=9Ft_bei=C3=9Ft?= <biter@example.com>\n')
 
+    def test_address_list_with_list_separator_after_fold(self):
+        to = '0123456789' * 8 + '@foo, ä <foo@bar>'
+        self._test(parser.get_address_list(to)[0],
+                   '0123456789' * 8 + '@foo,\n =?utf-8?q?=C3=A4?= <foo@bar>\n')
+
     # XXX Need tests with comments on various sides of a unicode token,
     # and with unicode tokens in the comments.  Spaces inside the quotes
     # currently don't do the right thing.
diff --git a/Misc/NEWS.d/next/Library/2023-01-09-14-08-02.gh-issue-100884.DcmdLl.rst b/Misc/NEWS.d/next/Library/2023-01-09-14-08-02.gh-issue-100884.DcmdLl.rst
new file mode 100644 (file)
index 0000000..2a38817
--- /dev/null
@@ -0,0 +1,2 @@
+email: fix misfolding of comma in address-lists over multiple lines in
+combination with unicode encoding.