]> granicus.if.org Git - python/commitdiff
Issue #7143: get_payload used to strip any trailing newline from a
authorR. David Murray <rdmurray@bitdance.com>
Mon, 8 Mar 2010 02:04:06 +0000 (02:04 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Mon, 8 Mar 2010 02:04:06 +0000 (02:04 +0000)
base64 transfer-encoded payload *after* decoding it; it no longer does.
email had a special method in utils, _bdecode, specifically to do this,
so it must have served a purpose at some point, yet it is clearly wrong
per RFC.  Fixed with Barry's approval, but no backport.  Email package
minor version number is bumped, now version 4.0.1.

Patch by Joaquin Cuenca Abela.

Lib/email/__init__.py
Lib/email/test/data/msg_10.txt
Lib/email/test/test_email.py
Lib/email/test/test_email_renamed.py
Lib/email/utils.py
Misc/ACKS
Misc/NEWS

index 8d230fdeb7d0300d7e331b2c58eb54910fd28837..a7934369198064cd6643bf44ea1416e73f02ecd5 100644 (file)
@@ -4,7 +4,7 @@
 
 """A package for parsing, handling, and generating email messages."""
 
-__version__ = '4.0.1'
+__version__ = '4.0.2'
 
 __all__ = [
     # Old names
index bd30d13ad1ae3c40ad84ac3ef958d802458880e1..07903960f9fe0de865ab7a7dfaa9264e2d6cd739 100644 (file)
@@ -24,6 +24,13 @@ Content-Transfer-Encoding: Base64
 VGhpcyBpcyBhIEJhc2U2NCBlbmNvZGVkIG1lc3NhZ2Uu
 
 
+--BOUNDARY
+Content-Type: text/plain; charset="iso-8859-1"
+Content-Transfer-Encoding: Base64
+
+VGhpcyBpcyBhIEJhc2U2NCBlbmNvZGVkIG1lc3NhZ2UuCg==
+
+
 --BOUNDARY
 Content-Type: text/plain; charset="iso-8859-1"
 
index aa16ce22695c48282b48256f543f2a21b9cb3320..36b308fd97c00c62be183ef1364845f7710a7429 100644 (file)
@@ -205,8 +205,12 @@ class TestMessageAPI(TestEmailBase):
         # Subpart 3 is base64
         eq(msg.get_payload(2).get_payload(decode=True),
            'This is a Base64 encoded message.')
-        # Subpart 4 has no Content-Transfer-Encoding: header.
+        # Subpart 4 is base64 with a trailing newline, which
+        # used to be stripped (issue 7143).
         eq(msg.get_payload(3).get_payload(decode=True),
+           'This is a Base64 encoded message.\n')
+        # Subpart 5 has no Content-Transfer-Encoding: header.
+        eq(msg.get_payload(4).get_payload(decode=True),
            'This has no Content-Transfer-Encoding: header.\n')
 
     def test_get_decoded_uu_payload(self):
index fc8f30a20f0975ee60bde1a71957ae59681117f0..976d892f4a7104b9a30bf14fcbe9b6e3fe2880d2 100644 (file)
@@ -194,8 +194,12 @@ class TestMessageAPI(TestEmailBase):
         # Subpart 3 is base64
         eq(msg.get_payload(2).get_payload(decode=True),
            'This is a Base64 encoded message.')
-        # Subpart 4 has no Content-Transfer-Encoding: header.
+        # Subpart 4 is base64 with a trailing newline, which
+        # used to be stripped (issue 7143).
         eq(msg.get_payload(3).get_payload(decode=True),
+           'This is a Base64 encoded message.\n')
+        # Subpart 5 has no Content-Transfer-Encoding: header.
+        eq(msg.get_payload(4).get_payload(decode=True),
            'This has no Content-Transfer-Encoding: header.\n')
 
     def test_get_decoded_uu_payload(self):
index b9a7642fb30df963723260ad300487a758a94954..6d22ca7e09eb8bafefc67a42b5cfb5c926fc6618 100644 (file)
@@ -60,14 +60,15 @@ def _identity(s):
 
 
 def _bdecode(s):
-    # We can't quite use base64.encodestring() since it tacks on a "courtesy
-    # newline".  Blech!
+    """Decodes a base64 string.
+
+    This function is equivalent to base64.decodestring and it's retained only
+    for backward compatibility. It used to remove the last \n of the decoded
+    string, if it had any (see issue 7143).
+    """
     if not s:
         return s
-    value = base64.decodestring(s)
-    if not s.endswith('\n') and value.endswith('\n'):
-        return value[:-1]
-    return value
+    return base64.decodestring(s)
 
 
 \f
index 426d0dd022bccf643f4e34f8ff06fec72c6839e3..09f478209aca641caedd64a42584a1173bde2add 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -10,6 +10,7 @@ Without you, I would've stopped working on Python long ago!
 
 PS: In the standard Python distribution, this file is encoded in UTF-8.
 
+Joaquin Cuenca Abela
 David Abrahams
 Jim Ahlstrom
 Farhan Ahmad
index b1431a3e0050e6b036ddbd7f3cb640db6049be45..1f16de8d8dbf4fb3c4c93d8b0cd47b8917abcd6d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,11 @@ Core and Builtins
 Library
 -------
 
+- Issue #7143: get_payload used to strip any trailing newline from a
+  base64 transfer-encoded payload *after* decoding it; it no longer does.
+  This is a behavior change, so email's minor version number is now
+  bumped, to version 4.0.2, for the 2.7 release.
+
 Extension Modules
 -----------------
 
@@ -28,6 +33,7 @@ Extension Modules
   and standard packing.)
 
 
+
 What's New in Python 2.7 alpha 4?
 =================================