mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-142006: Fix HeaderWriteError in email.policy.default caused by extra newline (#142008)
RDM: This fixes a subtle folding error that showed up when a token exactly filled a line and was followed by whitespace and a token with no folding whitespace that was longer than a line. In this particular circumstance the whitespace after the first token got pushed on to the next line, and then stolen to go in front of the next unfoldable token...leaving a completely empty line in the line buffer. That line got turned in to a newline, which is RFC illegal, and the newish security check caught it. The fix is to just delete that empty line from the buffer. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
parent
100e316e53
commit
07eff899d8
3 changed files with 14 additions and 0 deletions
|
|
@ -3255,5 +3255,15 @@ def test_long_filename_attachment(self):
|
|||
" filename*1*=_TEST_TES.txt\n",
|
||||
)
|
||||
|
||||
def test_fold_unfoldable_element_stealing_whitespace(self):
|
||||
# gh-142006: When an element is too long to fit on the current line
|
||||
# the previous line's trailing whitespace should not trigger a double newline.
|
||||
policy = self.policy.clone(max_line_length=10)
|
||||
# The non-whitespace text needs to exactly fill the max_line_length (10).
|
||||
text = ("a" * 9) + ", " + ("b" * 20)
|
||||
expected = ("a" * 9) + ",\n " + ("b" * 20) + "\n"
|
||||
token = parser.get_address_list(text)[0]
|
||||
self._test(token, expected, policy=policy)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue