From b0614e033b466da9e322140595faab39b9819c23 Mon Sep 17 00:00:00 2001 From: Joel Hillacre Date: Wed, 31 May 2017 16:46:25 -0600 Subject: [PATCH 1/5] make stickyspace contain the popped space, not the next part. --- Lib/email/_header_value_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py index 57d01fbcb0f2c28..a7746abe53c237c 100644 --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -343,7 +343,7 @@ def _fold(self, folded): 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 = ws if folded.append_if_fits(part): continue if part.has_fws: From beacc7c449f4878298e2335b1f27a6cf34474e72 Mon Sep 17 00:00:00 2001 From: Joel Hillacre Date: Wed, 31 May 2017 17:27:42 -0600 Subject: [PATCH 2/5] adding tests for bpo-30532 --- Lib/test/test_email/test__header_value_parser.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py index 26ece6911f23777..e0ec87d2080185d 100644 --- a/Lib/test/test_email/test__header_value_parser.py +++ b/Lib/test/test_email/test__header_value_parser.py @@ -2711,5 +2711,17 @@ def test_whitespace_splitting(self): 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() From 0c85101c3d0a7686f30a5296a07dc70a3ff2fed3 Mon Sep 17 00:00:00 2001 From: Joel Hillacre Date: Wed, 31 May 2017 20:16:28 -0600 Subject: [PATCH 3/5] remove the repeated comment from above --- Lib/email/_header_value_parser.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py index a7746abe53c237c..72b5cfc4fa1e054 100644 --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -341,8 +341,6 @@ def _fold(self, folded): # 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 = ws if folded.append_if_fits(part): continue From ec63c3c2ff4baa58b4627bfd051d4646a15b2272 Mon Sep 17 00:00:00 2001 From: Joel Hillacre Date: Mon, 26 Jun 2017 11:04:15 -0600 Subject: [PATCH 4/5] update Misc/ACKS and add Misc/NEWS.d entry. --- Misc/ACKS | 1 + .../NEWS.d/next/Library/2017-06-26-11-01-59.bpo-30532.qTeL1o.rst | 1 + 2 files changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2017-06-26-11-01-59.bpo-30532.qTeL1o.rst diff --git a/Misc/ACKS b/Misc/ACKS index 3000bc36d2c6213..4cfe87132ac749c 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -628,6 +628,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 index 000000000000000..adce85fbc2b4c64 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-06-26-11-01-59.bpo-30532.qTeL1o.rst @@ -0,0 +1 @@ +Fix email header value parser dropping folding white space in certain cases. From 29f92f0d91b6edb8792717a83c72ad9f141ac434 Mon Sep 17 00:00:00 2001 From: Joel Hillacre Date: Mon, 26 Jun 2017 11:08:16 -0600 Subject: [PATCH 5/5] add str() wrapping for consistancy with similar logic elsewhere. --- Lib/email/_header_value_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py index 72b5cfc4fa1e054..9b9697f77346a60 100644 --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -341,7 +341,7 @@ def _fold(self, folded): # avoid infinite recursion. ws = part.pop_leading_fws() if ws is not None: - folded.stickyspace = ws + folded.stickyspace = str(ws) if folded.append_if_fits(part): continue if part.has_fws: