]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-128110: Fix rfc2047 whitespace handling in email parser address headers (#130749)
authorMike Edmunds <medmunds@gmail.com>
Mon, 11 May 2026 22:20:09 +0000 (15:20 -0700)
committerGitHub <noreply@github.com>
Mon, 11 May 2026 22:20:09 +0000 (18:20 -0400)
commit7a4c6dfb8839eb05fb87baf70364680e45001dd4
tree07f28d7c26e2215283fa8ea4b6b928f730d5e74e
parent8a4895985f42282504d83b9bd0c77b129f95a5d5
gh-128110: Fix rfc2047 whitespace handling in email parser address headers (#130749)

RFC 2047 Section 6.2 requires that "any 'linear-white-space' that
separates a pair of adjacent 'encoded-word's is ignored." The modern
header value parser correctly implements that for unstructured headers,
but had missed a case in structured headers. This could cause a parsed
address header to include extraneous spaces in a display-name.

Switch to @bitdancer's fix from review feedback. Recharacterize space
between ews as fws after parsing in get_phrase.

RDM: This fix is dependent on the fact that "subsequent" atoms will never have
leading whitespace because that's been consumed already. I don't think
it's worth adding extra code for the possibility of leading whitespace
because the parser won't produce it. It's a bit of parser fragility in the
face of code changes, but I think that's a minor concern given the
parser design (which is that it consumes whitespace greedily)

Co-authored-by: R David Murray <rdmurray@bitdance.com>
Lib/email/_header_value_parser.py
Lib/test/test_email/test__header_value_parser.py
Misc/NEWS.d/next/Library/2025-03-01-13-36-02.gh-issue-128110.9wx_G0.rst [new file with mode: 0644]