]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-120930: Remove extra blank occuring in wrapped encoded words in email headers...
authorMatthieu Caneill <matthieucan@users.noreply.github.com>
Thu, 18 Jul 2024 12:48:05 +0000 (14:48 +0200)
committerGitHub <noreply@github.com>
Thu, 18 Jul 2024 12:48:05 +0000 (14:48 +0200)
Lib/email/_header_value_parser.py
Lib/test/test_email/test_generator.py
Misc/NEWS.d/next/Library/2024-07-14-11-18-28.gh-issue-120930.Kuo4L0.rst [new file with mode: 0644]

index ab3c3031ef590c2dd6666ebe0f7845179c305854..7da1bbaf8a80d72b1418acc2a78b3ae3b693c30e 100644 (file)
@@ -2988,6 +2988,7 @@ def _fold_as_ew(to_encode, lines, maxlen, last_ew, ew_combine_allowed, charset,
             excess = len(encoded_word) - remaining_space
         lines[-1] += encoded_word
         to_encode = to_encode[len(to_encode_word):]
+        leading_whitespace = ''
 
         if to_encode:
             lines.append(' ')
index bfff10512620792f4b56feb346326283ad96b75e..bc6f734d4fd0a9e14e6e9331062d5c9101b548cc 100644 (file)
@@ -294,6 +294,19 @@ class TestBytesGenerator(TestGeneratorBase, TestEmailBase):
         g.flatten(msg)
         self.assertEqual(s.getvalue(), expected)
 
+    def test_defaults_handle_spaces_when_encoded_words_is_folded_in_middle(self):
+        source = ('A very long long long long long long long long long long long long '
+                  'long long long long long long long long long long long súmmäry')
+        expected = ('Subject: A very long long long long long long long long long long long long\n'
+                    ' long long long long long long long long long long long =?utf-8?q?s=C3=BAmm?=\n'
+                    ' =?utf-8?q?=C3=A4ry?=\n\n').encode('ascii')
+        msg = EmailMessage()
+        msg['Subject'] = source
+        s = io.BytesIO()
+        g = BytesGenerator(s)
+        g.flatten(msg)
+        self.assertEqual(s.getvalue(), expected)
+
     def test_defaults_handle_spaces_at_start_of_subject(self):
         source = " Уведомление"
         expected = b"Subject:  =?utf-8?b?0KPQstC10LTQvtC80LvQtdC90LjQtQ==?=\n\n"
diff --git a/Misc/NEWS.d/next/Library/2024-07-14-11-18-28.gh-issue-120930.Kuo4L0.rst b/Misc/NEWS.d/next/Library/2024-07-14-11-18-28.gh-issue-120930.Kuo4L0.rst
new file mode 100644 (file)
index 0000000..9e11595
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed a bug introduced by gh-92081 that added an incorrect extra
+blank to encoded words occurring in wrapped headers.