[Python-checkins] bpo-43125: Fix: return expected type (str), not original value (bytes) in email/base64mime.py::body_encode (GH-24476)

corona10 webhook-mailer at python.org
Tue Mar 30 04:37:45 EDT 2021


https://github.com/python/cpython/commit/cf35e05f89bb008d6f4553f9875e0fe87fc02406
commit: cf35e05f89bb008d6f4553f9875e0fe87fc02406
branch: master
author: Grégory Starck <g.starck at gmail.com>
committer: corona10 <donghee.na92 at gmail.com>
date: 2021-03-30T17:37:37+09:00
summary:

bpo-43125: Fix: return expected type (str), not original value (bytes) in email/base64mime.py::body_encode (GH-24476)

files:
A Misc/NEWS.d/next/Library/2021-02-07-19-13-30.bpo-43125.AqNoMa.rst
M Lib/email/base64mime.py
M Lib/test/test_email/test_email.py

diff --git a/Lib/email/base64mime.py b/Lib/email/base64mime.py
index 17f0818f6caa8..a7cc37365c6f9 100644
--- a/Lib/email/base64mime.py
+++ b/Lib/email/base64mime.py
@@ -84,7 +84,7 @@ def body_encode(s, maxlinelen=76, eol=NL):
     in an email.
     """
     if not s:
-        return s
+        return ""
 
     encvec = []
     max_unencoded = maxlinelen * 3 // 4
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 044b93862a14e..720a63b4e48ff 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -4261,7 +4261,7 @@ def test_decode(self):
 
     def test_encode(self):
         eq = self.assertEqual
-        eq(base64mime.body_encode(b''), b'')
+        eq(base64mime.body_encode(b''), '')
         eq(base64mime.body_encode(b'hello'), 'aGVsbG8=\n')
         # Test the binary flag
         eq(base64mime.body_encode(b'hello\n'), 'aGVsbG8K\n')
@@ -4292,7 +4292,6 @@ def test_header_encode(self):
         eq(he('hello\nworld'), '=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=')
 
 
-
 class TestQuopri(unittest.TestCase):
     def setUp(self):
         # Set of characters (as byte integers) that don't need to be encoded
diff --git a/Misc/NEWS.d/next/Library/2021-02-07-19-13-30.bpo-43125.AqNoMa.rst b/Misc/NEWS.d/next/Library/2021-02-07-19-13-30.bpo-43125.AqNoMa.rst
new file mode 100644
index 0000000000000..4c4a5836d2595
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-02-07-19-13-30.bpo-43125.AqNoMa.rst
@@ -0,0 +1 @@
+Return empty string if base64mime.body_encode receive empty bytes



More information about the Python-checkins mailing list