Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1292a2

Browse files
committed
#11492: fix header truncation on folding when there are runs of split chars.
Not a complete fix for this issue.
1 parent 7da4db1 commit e1292a2

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Lib/email/header.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,13 @@ def _ascii_split(self, string, ch):
464464
self._current_line.reset(str(holding))
465465
return
466466
elif not nextpart:
467-
# There must be some trailing split characters because we
467+
# There must be some trailing or duplicated split characters
468+
# because we
468469
# found a split character but no next part. In this case we
469470
# must treat the thing to fit as the part + splitpart because
470471
# if splitpart is whitespace it's not allowed to be the only
471472
# thing on the line, and if it's not whitespace we must split
472-
# after the syntactic break. In either case, we're done.
473+
# after the syntactic break.
473474
holding_prelen = len(holding)
474475
holding.push(part + splitpart)
475476
if len(holding) + len(self._current_line) <= self._maxlen:
@@ -484,7 +485,7 @@ def _ascii_split(self, string, ch):
484485
self._lines.append(str(self._current_line))
485486
holding.reset(save_part)
486487
self._current_line.reset(str(holding))
487-
return
488+
holding.reset()
488489
elif not part:
489490
# We're leading with a split character. See if the splitpart
490491
# and nextpart fits on the current line.

Lib/email/test/test_email.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,16 @@ def test_trailing_splitable_on_overlong_unsplitable_with_leading_splitable(self)
793793
;
794794
this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;""")
795795

796+
def test_long_header_with_multiple_sequential_split_chars(self):
797+
# Issue 11492
798+
799+
eq = self.ndiffAssertEqual
800+
h = Header('This is a long line that has two whitespaces in a row. '
801+
'This used to cause truncation of the header when folded')
802+
eq(h.encode(), """\
803+
This is a long line that has two whitespaces in a row. This used to cause
804+
truncation of the header when folded""")
805+
796806
def test_no_split_long_header(self):
797807
eq = self.ndiffAssertEqual
798808
hstr = 'References: ' + 'x' * 80

0 commit comments

Comments
 (0)