diff options
author | Joel Hillacre <joel@403forbidden.ca> | 2017-07-06 21:29:09 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2017-07-06 21:29:09 (GMT) |
commit | 3bbdf990a2c1b0b303b950058e3177a1bd5f697a (patch) | |
tree | b2ebc2b052ae6ab7547d4101590ee7545c0d4c70 | |
parent | 710cc7667c27955272725729775cb39c40cca113 (diff) | |
download | cpython-3bbdf990a2c1b0b303b950058e3177a1bd5f697a.zip cpython-3bbdf990a2c1b0b303b950058e3177a1bd5f697a.tar.gz cpython-3bbdf990a2c1b0b303b950058e3177a1bd5f697a.tar.bz2 |
bpo-30532: Fix whitespace folding in certain cases (#2592)
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.
-rw-r--r-- | Lib/email/_header_value_parser.py | 4 | ||||
-rw-r--r-- | Lib/test/test_email/test__header_value_parser.py | 12 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2017-06-26-11-01-59.bpo-30532.qTeL1o.rst | 1 |
4 files changed, 15 insertions, 3 deletions
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py index 5df9511..37a9fbc 100644 --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -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: diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py index f7ac0e3..b1e7dff 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 @@ 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() @@ -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 index 0000000..adce85f --- /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. |