]> granicus.if.org Git - python/commitdiff
bpo-30532: Fix whitespace folding in certain cases
authorJoel Hillacre <joel@403forbidden.ca>
Mon, 26 Jun 2017 21:41:35 +0000 (15:41 -0600)
committerR. David Murray <rdmurray@bitdance.com>
Mon, 26 Jun 2017 21:41:35 +0000 (17:41 -0400)
Leading whitespace was incorrectly dropped during folding of certain lines in the _header_value_parser's folding algorithm.  This makes the whitespace handling code consistent.

Lib/email/_header_value_parser.py
Lib/test/test_email/test__header_value_parser.py
Misc/ACKS
Misc/NEWS.d/next/Library/2017-06-26-11-01-59.bpo-30532.qTeL1o.rst [new file with mode: 0644]

index 57d01fbcb0f2c2868426ffd4051118558f86c989..9b9697f77346a60ab37321f46c4b58845135bd1a 100644 (file)
@@ -341,9 +341,7 @@ class TokenList(list):
             # avoid infinite recursion.
             ws = part.pop_leading_fws()
             if ws is not None:
-                # Peel off the leading whitespace and make it sticky, to
-                # avoid infinite recursion.
-                folded.stickyspace = str(part.pop(0))
+                folded.stickyspace = str(ws)
                 if folded.append_if_fits(part):
                     continue
             if part.has_fws:
index 26ece6911f2377776e9456b53b8a08cefa367e8b..e0ec87d2080185d5a9eac459470c07694d2ad5ab 100644 (file)
@@ -2711,5 +2711,17 @@ class TestFolding(TestEmailBase):
         self._test(parser.get_unstructured('xxx   ' + 'y'*77),
                    'xxx  \n ' + 'y'*77 + '\n')
 
+    def test_long_filename_attachment(self):
+        folded = self.policy.fold('Content-Disposition', 'attachment; filename="TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TES.txt"')
+        self.assertEqual(
+            'Content-Disposition: attachment;\n filename="TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TES.txt"\n',
+            folded
+        )
+        folded = self.policy.fold('Content-Disposition', 'attachment; filename="TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_T.txt"')
+        self.assertEqual(
+            'Content-Disposition: attachment;\n filename="TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_T.txt"\n',
+            folded
+        )
+
 if __name__ == '__main__':
     unittest.main()
index eaff17232c9a12dda26801f84bdb21885cc28ff6..89cd1fa10a0757ce1de798e4f29979898ac341c5 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -630,6 +630,7 @@ Wouter van Heyst
 Kelsey Hightower
 Jason Hildebrand
 Aaron Hill
+Joel Hillacre
 Richie Hindle
 Konrad Hinsen
 David Hobley
diff --git a/Misc/NEWS.d/next/Library/2017-06-26-11-01-59.bpo-30532.qTeL1o.rst b/Misc/NEWS.d/next/Library/2017-06-26-11-01-59.bpo-30532.qTeL1o.rst
new file mode 100644 (file)
index 0000000..adce85f
--- /dev/null
@@ -0,0 +1 @@
+Fix email header value parser dropping folding white space in certain cases.