-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-142006: Fix HeaderWriteError in email.policy.default caused by extra newline #142008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
42d48ed to
328bbac
Compare
bitdancer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for finding and fixing this bug.
Misc/NEWS.d/next/Library/2025-11-27-10-49-13.gh-issue-142006.nzJDG5.rst
Outdated
Show resolved
Hide resolved
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
Thanks @bitdancer! I have made the requested changes; please review again.
Please review again. |
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @bitdancer: please review the changes made to this pull request. |
Description
This PR fixes
gh-142006whereemail.policy.defaultwould raise aHeaderWriteErrorwhen folding certain long address headers.The Issue:
In
_header_value_parser.py, the function_steal_trailing_WSP_if_existsmoves trailing whitespace from the previous line to the current one. However, if the previous line contained only that whitespace, it was left as an empty string''. When joined, this resulted in a double newline (\n\n), which is illegal in headers and triggered the error.The Fix:
Modified
_steal_trailing_WSP_if_existsto remove the line entirely (lines.pop()) if it becomes empty after stealing the whitespace.Verification:
Added a regression test
test_fold_address_list_with_stolen_whitespacetoLib/test/test_email/test_policy.pywhich reproduces the reported crash and verifies the fix.Linked Issue
Fixes gh-142006