gh-145831: email.quoprimime: decode() leaves stray \r when eol='\r\n'#145832
Merged
bitdancer merged 6 commits intopython:mainfrom Apr 9, 2026
Merged
Conversation
decoded[:-1] only strips one character, leaving a stray \r when eol is two characters. Fix: decoded[:-len(eol)].
…il_quoprimime_crlf_stray_cr
bitdancer
approved these changes
Apr 9, 2026
|
Thanks @stefanzetzsche for the PR, and @bitdancer for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
Thanks @stefanzetzsche for the PR, and @bitdancer for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Apr 9, 2026
…`eol='\r\n'` (pythonGH-145832) decoded[:-1] only strips one character, leaving a stray \r when eol is two characters. Fix: decoded[:-len(eol)]. (cherry picked from commit 1a0edb1) Co-authored-by: Stefan Zetzsche <120379523+stefanzetzsche@users.noreply.github.com>
|
GH-148311 is a backport of this pull request to the 3.13 branch. |
|
GH-148312 is a backport of this pull request to the 3.14 branch. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Apr 9, 2026
…`eol='\r\n'` (pythonGH-145832) decoded[:-1] only strips one character, leaving a stray \r when eol is two characters. Fix: decoded[:-len(eol)]. (cherry picked from commit 1a0edb1) Co-authored-by: Stefan Zetzsche <120379523+stefanzetzsche@users.noreply.github.com>
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.
Issue
email.quoprimime.decode()doesdecoded[:-1]to strip a trailing line ending, but this only removes one character. Wheneol='\r\n'(2 characters), a stray\ris left in the output.Reproducer
Fix
In
Lib/email/quoprimime.py, change:to:
Tests
Three test cases added to
TestQuopriinLib/test/test_email/test_email.py:test_decode_crlf_eol_no_trailing_newline— verifiesdecode('abc', eol='\r\n')returns'abc'(direct reproducer for the bug; without the fix, returns'abc\r').test_decode_crlf_eol_multiline_no_trailing_newline— verifiesdecode('a\r\nb', eol='\r\n')returns'a\r\nb'(multi-line input without trailing newline).test_decode_crlf_eol_with_trailing_newline— verifiesdecode('abc\r\n', eol='\r\n')returns'abc\r\n'(trailing newline is legitimate and should be preserved).