Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.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 ourterms of service andprivacy 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 to328bbacCompare
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.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Misc/NEWS.d/next/Library/2025-11-27-10-49-13.gh-issue-142006.nzJDG5.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
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 |
pareshjoshij commentedNov 28, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks@bitdancer! I have made the requested changes; please review again.
Please review again. |
pareshjoshij commentedNov 28, 2025
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 containedonly 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
Fixesgh-142006