]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] gh-124452: Fix header mismatches when folding/unfolding with email message...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 17 Nov 2024 20:06:18 +0000 (21:06 +0100)
committerGitHub <noreply@github.com>
Sun, 17 Nov 2024 20:06:18 +0000 (15:06 -0500)
commitaf35aa288064c24899b0bac161a20eaf619b829d
treefda6a3160e352645c3b9824a520628800dca0e67
parent52efb95b4527617633c43158c8b73e1c985f28fb
[3.13] gh-124452: Fix header mismatches when folding/unfolding with email message (GH-125919) (#126917)

gh-124452: Fix header mismatches when folding/unfolding with email message (GH-125919)

The header-folder of the new email API has a long standing known buglet where
if the first token is longer than max_line_length, it puts that token on the next
line.  It turns out there is also a *parsing* bug when parsing such a header:
the space prefixing that first, non-empty line gets preserved and tacked on to
the start of the header value, which is not the expected behavior per the RFCs.
The bug arises from the fact that the parser assumed that there would be at
least one token on the line with the header, which is going to be true for
probably every email producer other than the python email library with its
folding buglet.  Clearly, though, this is a case that needs to be handled
correctly.  The fix is simple: strip the blanks off the start of the whole
value, not just the first physical line of the value.

(cherry picked from commit ed81971e6b26c34445f06850192b34458b029337)

Co-authored-by: RanKKI <hliu86.me@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Lib/email/_policybase.py
Lib/email/policy.py
Lib/test/test_email/test_message.py
Misc/NEWS.d/next/Library/2024-10-24-10-49-47.gh-issue-124452.eqTRgx.rst [new file with mode: 0644]