https://github.com/python/cpython/commit/e8f3f7668f44ac83aa61f3ba0afe10e150b9fc21
commit: e8f3f7668f44ac83aa61f3ba0afe10e150b9fc21
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: bitdancer <[email protected]>
date: 2026-04-10T08:49:59-04:00
summary:

[3.14] gh-145831: email.quoprimime: `decode()` leaves stray `\r` when 
`eol='\r\n'` (GH-145832) (#148312)

decoded[:-1] only strips one character, leaving a stray \r when eol
is two characters. Fix: decoded[:-len(eol)].
(cherry picked from commit 1a0edb1fa899c067f19b09598b45cdb6e733c4ee)

Co-authored-by: Stefan Zetzsche 
<[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-03-11-15-09-52.gh-issue-145831._sW94w.rst
M Lib/email/quoprimime.py
M Lib/test/test_email/test_email.py

diff --git a/Lib/email/quoprimime.py b/Lib/email/quoprimime.py
index 27c7ea55c7871f..bc53b376821310 100644
--- a/Lib/email/quoprimime.py
+++ b/Lib/email/quoprimime.py
@@ -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
 
 
diff --git a/Lib/test/test_email/test_email.py 
b/Lib/test/test_email/test_email.py
index 0f138182fda2ba..3ba3e86ab65bd7 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -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:
diff --git 
a/Misc/NEWS.d/next/Library/2026-03-11-15-09-52.gh-issue-145831._sW94w.rst 
b/Misc/NEWS.d/next/Library/2026-03-11-15-09-52.gh-issue-145831._sW94w.rst
new file mode 100644
index 00000000000000..454b62bc0db95f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-03-11-15-09-52.gh-issue-145831._sW94w.rst
@@ -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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to