]> granicus.if.org Git - python/commitdiff
bpo-30532: Fix whitespace folding in certain cases (#2592)
authorJoel Hillacre <joel@403forbidden.ca>
Thu, 6 Jul 2017 21:29:09 +0000 (15:29 -0600)
committerR. David Murray <rdmurray@bitdance.com>
Thu, 6 Jul 2017 21:29:09 +0000 (17:29 -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 5df9511e8d90647e9fae9caa40652b0fc340dd02..37a9fbcbb67d7c06afc4dff2aafc9e6b1d38d195 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 f7ac0e3dedcc243c988d7413126104fe9fcf74a1..b1e7dff2405d882897ab673de35efa9c558c3f6d 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 5440326ac3346aa0a655ccb94f58c98f7371d0d0..fbf110d801b5aac278f8e38e0abc3020c85426f3 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -612,6 +612,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.