bpo-30532: Fix whitespace folding in certain cases (#2591)

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.
This commit is contained in:
Joel Hillacre 2017-07-06 15:28:22 -06:00 committed by R. David Murray
parent 5d2550cd2e
commit c60d2f5e86
4 changed files with 15 additions and 3 deletions

View file

@ -341,9 +341,7 @@ class TokenList(list):
# avoid infinite recursion. # avoid infinite recursion.
ws = part.pop_leading_fws() ws = part.pop_leading_fws()
if ws is not None: if ws is not None:
# Peel off the leading whitespace and make it sticky, to folded.stickyspace = str(ws)
# avoid infinite recursion.
folded.stickyspace = str(part.pop(0))
if folded.append_if_fits(part): if folded.append_if_fits(part):
continue continue
if part.has_fws: if part.has_fws:

View file

@ -2711,5 +2711,17 @@ class TestFolding(TestEmailBase):
self._test(parser.get_unstructured('xxx ' + 'y'*77), self._test(parser.get_unstructured('xxx ' + 'y'*77),
'xxx \n ' + 'y'*77 + '\n') '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__': if __name__ == '__main__':
unittest.main() unittest.main()

View file

@ -624,6 +624,7 @@ Wouter van Heyst
Kelsey Hightower Kelsey Hightower
Jason Hildebrand Jason Hildebrand
Aaron Hill Aaron Hill
Joel Hillacre
Richie Hindle Richie Hindle
Konrad Hinsen Konrad Hinsen
David Hobley David Hobley

View file

@ -0,0 +1 @@
Fix email header value parser dropping folding white space in certain cases.