bpo-27737: Allow whitespace only headers encoding (#13478)
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
Thu, 23 May 2019 01:13:16 +0000 (04:13 +0300)
committerR. David Murray <rdmurray@bitdance.com>
Thu, 23 May 2019 01:13:16 +0000 (21:13 -0400)
Lib/email/header.py
Lib/test/test_email/test_email.py
Misc/NEWS.d/next/Library/2019-05-22-02-25-31.bpo-27737.7bgKpa.rst [new file with mode: 0644]

index 7b30a039da1c46e03f366ae2ff362eb717cbc10c..4ab0032bc661234a2ad212c16568d340e479bba5 100644 (file)
@@ -431,7 +431,7 @@ class _ValueFormatter:
         if end_of_line != (' ', ''):
             self._current_line.push(*end_of_line)
         if len(self._current_line) > 0:
-            if self._current_line.is_onlyws():
+            if self._current_line.is_onlyws() and self._lines:
                 self._lines[-1] += str(self._current_line)
             else:
                 self._lines.append(str(self._current_line))
index 621754cf753daa2a79a7f4811d3944ed8a90d1d9..dfb3be84384a8b26b1198f488f269bc6d2e3b98d 100644 (file)
@@ -4964,6 +4964,9 @@ A very long line that must get split to something other than at the
         msg['SomeHeader'] = '   value with leading ws'
         self.assertEqual(str(msg), "SomeHeader:    value with leading ws\n\n")
 
+    def test_whitespace_header(self):
+        self.assertEqual(Header(' ').encode(), ' ')
+
 
 
 # Test RFC 2231 header parameters (en/de)coding
diff --git a/Misc/NEWS.d/next/Library/2019-05-22-02-25-31.bpo-27737.7bgKpa.rst b/Misc/NEWS.d/next/Library/2019-05-22-02-25-31.bpo-27737.7bgKpa.rst
new file mode 100644 (file)
index 0000000..02d0ef8
--- /dev/null
@@ -0,0 +1,2 @@
+Allow whitespace only header encoding in ``email.header`` - by Batuhan
+Taskaya