#11401: handle headers with no value.
authorR David Murray <rdmurray@bitdance.com>
Wed, 16 Mar 2011 22:26:23 +0000 (18:26 -0400)
committerR David Murray <rdmurray@bitdance.com>
Wed, 16 Mar 2011 22:26:23 +0000 (18:26 -0400)
Lib/email/header.py
Lib/email/test/test_email.py
Misc/NEWS

index 43220df762095f6a75206f4ac6b4a70f31cb9242..da739d58925d93d73335d0cd58081f4e981a5086 100644 (file)
@@ -304,7 +304,7 @@ class Header:
                                     self._continuation_ws, splitchars)
         for string, charset in self._chunks:
             lines = string.splitlines()
-            formatter.feed(lines[0], charset)
+            formatter.feed(lines[0] if lines else '', charset)
             for line in lines[1:]:
                 formatter.newline()
                 if charset.header_encoding is not None:
index 6a88b1670fc9587642a9a120fc252b0423985b7c..4268a25996f9426a264d9c4013d5546064287d28 100644 (file)
@@ -3296,6 +3296,13 @@ A very long line that must get split to something other than at the
         h = Header('文', charset='shift_jis')
         self.assertEqual(h.encode(), '=?iso-2022-jp?b?GyRCSjgbKEI=?=')
 
+    def test_flatten_header_with_no_value(self):
+        # Issue 11401 (regression from email 4.x)  Note that the space after
+        # the header doesn't reflect the input, but this is also the way
+        # email 4.x behaved.  At some point it would be nice to fix that.
+        msg = email.message_from_string("EmptyHeader:")
+        self.assertEqual(str(msg), "EmptyHeader: \n\n")
+
 
 
 # Test RFC 2231 header parameters (en/de)coding
index beb6ec1c1210cb8f7f5381b8151ba5003e8484bc..58eea2d3a1d9c79e2b92ef161a8210d546551579 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #11401: fix handling of headers with no value; this fixes a regression
+  relative to Python2 and the result is now the same as it was in Python2.
+
 - Issue #9298: base64 bodies weren't being folded to line lengths less than 78,
   which was a regression relative to Python2.  Unlike Python2, the last line
   of the folded body now ends with a carriage return.