Repository navigation
gh-159858: Fix memoryview payloads with 7bit, 8bit and binary email CTEs - #159859
Open
NikitaMikhailov wants to merge 2 commits into
Open
NikitaMikhailov wants to merge 2 commits into
NikitaMikhailov wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes gh-159858.
EmailMessage.set_content() accepts memoryview through the raw data manager's registered bytes handler, but the 7bit, 8bit, and binary branches call a decode() method that memoryview does not provide.
Decode the buffer directly with str(data, encoding, errors). This preserves ASCII validation for 7bit and surrogateescape handling for 8bit and binary, without an intermediate bytes copy.
Regression tests cover bytes, bytearray, and memoryview payloads with all three transfer encodings, including binary data round trips and rejection of non-ASCII 7bit input.
Validation:
Includes a Library NEWS entry.
AI assistance: Codex helped prepare the fix and tests and run validation.