mirror of https://github.com/python/cpython
#11492: fix header truncation on folding when there are runs of split chars.
Not a complete fix for this issue.
This commit is contained in:
parent
7da4db118e
commit
e1292a25d8
|
@ -464,12 +464,13 @@ class _ValueFormatter:
|
||||||
self._current_line.reset(str(holding))
|
self._current_line.reset(str(holding))
|
||||||
return
|
return
|
||||||
elif not nextpart:
|
elif not nextpart:
|
||||||
# There must be some trailing split characters because we
|
# There must be some trailing or duplicated split characters
|
||||||
|
# because we
|
||||||
# found a split character but no next part. In this case we
|
# found a split character but no next part. In this case we
|
||||||
# must treat the thing to fit as the part + splitpart because
|
# must treat the thing to fit as the part + splitpart because
|
||||||
# if splitpart is whitespace it's not allowed to be the only
|
# if splitpart is whitespace it's not allowed to be the only
|
||||||
# thing on the line, and if it's not whitespace we must split
|
# thing on the line, and if it's not whitespace we must split
|
||||||
# after the syntactic break. In either case, we're done.
|
# after the syntactic break.
|
||||||
holding_prelen = len(holding)
|
holding_prelen = len(holding)
|
||||||
holding.push(part + splitpart)
|
holding.push(part + splitpart)
|
||||||
if len(holding) + len(self._current_line) <= self._maxlen:
|
if len(holding) + len(self._current_line) <= self._maxlen:
|
||||||
|
@ -484,7 +485,7 @@ class _ValueFormatter:
|
||||||
self._lines.append(str(self._current_line))
|
self._lines.append(str(self._current_line))
|
||||||
holding.reset(save_part)
|
holding.reset(save_part)
|
||||||
self._current_line.reset(str(holding))
|
self._current_line.reset(str(holding))
|
||||||
return
|
holding.reset()
|
||||||
elif not part:
|
elif not part:
|
||||||
# We're leading with a split character. See if the splitpart
|
# We're leading with a split character. See if the splitpart
|
||||||
# and nextpart fits on the current line.
|
# and nextpart fits on the current line.
|
||||||
|
|
|
@ -793,6 +793,16 @@ Subject: the first part of this is short,
|
||||||
;
|
;
|
||||||
this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;""")
|
this_part_does_not_fit_within_maxlinelen_and_thus_should_be_on_a_line_all_by_itself;""")
|
||||||
|
|
||||||
|
def test_long_header_with_multiple_sequential_split_chars(self):
|
||||||
|
# Issue 11492
|
||||||
|
|
||||||
|
eq = self.ndiffAssertEqual
|
||||||
|
h = Header('This is a long line that has two whitespaces in a row. '
|
||||||
|
'This used to cause truncation of the header when folded')
|
||||||
|
eq(h.encode(), """\
|
||||||
|
This is a long line that has two whitespaces in a row. This used to cause
|
||||||
|
truncation of the header when folded""")
|
||||||
|
|
||||||
def test_no_split_long_header(self):
|
def test_no_split_long_header(self):
|
||||||
eq = self.ndiffAssertEqual
|
eq = self.ndiffAssertEqual
|
||||||
hstr = 'References: ' + 'x' * 80
|
hstr = 'References: ' + 'x' * 80
|
||||||
|
|
Loading…
Reference in New Issue