Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-145831: email.quoprimime: decode() leaves stray \r when `eol='…
…\r\n'` (GH-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>
  • Loading branch information
stefanzetzsche authored and miss-islington committed Apr 9, 2026
commit a296e280b8fa8bd75e6584115c7d8a43c38ad8a8
2 changes: 1 addition & 1 deletion Lib/email/quoprimime.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def decode(encoded, eol=NL):
decoded += eol
# Special case if original string did not end with eol
if encoded[-1] not in '\r\n' and decoded.endswith(eol):
decoded = decoded[:-1]
decoded = decoded[:-len(eol)]
return decoded


Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -4827,6 +4827,15 @@ def test_decode_soft_line_break(self):
def test_decode_false_quoting(self):
self._test_decode('A=1,B=A ==> A+B==2', 'A=1,B=A ==> A+B==2')

def test_decode_crlf_eol_no_trailing_newline(self):
self._test_decode('abc', 'abc', eol='\r\n')

def test_decode_crlf_eol_multiline_no_trailing_newline(self):
self._test_decode('a\r\nb', 'a\r\nb', eol='\r\n')

def test_decode_crlf_eol_with_trailing_newline(self):
self._test_decode('abc\r\n', 'abc\r\n', eol='\r\n')

def _test_encode(self, body, expected_encoded_body, maxlinelen=None, eol=None):
kwargs = {}
if maxlinelen is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`!email.quoprimime.decode` leaving a stray ``\r`` when
``eol='\r\n'`` by stripping the full *eol* string instead of one character.
Loading