[Python-checkins] bpo-27737: Allow whitespace only headers encoding (GH-13478) (#13517)

R. David Murray webhook-mailer at python.org
Wed May 22 21:41:48 EDT 2019


https://github.com/python/cpython/commit/0416d6f05a96e0f1b3751aa97abfffe6d3323976
commit: 0416d6f05a96e0f1b3751aa97abfffe6d3323976
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: R. David Murray <rdmurray at bitdance.com>
date: 2019-05-22T21:41:43-04:00
summary:

bpo-27737: Allow whitespace only headers encoding (GH-13478) (#13517)

(cherry picked from commit ef5bb25e2d6147cd44be9c9b166525fb30485be0)

Co-authored-by: Batuhan Taşkaya <47358913+isidentical at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2019-05-22-02-25-31.bpo-27737.7bgKpa.rst
M Lib/email/header.py
M Lib/test/test_email/test_email.py

diff --git a/Lib/email/header.py b/Lib/email/header.py
index 7b30a039da1c..4ab0032bc661 100644
--- a/Lib/email/header.py
+++ b/Lib/email/header.py
@@ -431,7 +431,7 @@ def newline(self):
         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))
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 621754cf753d..dfb3be84384a 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -4964,6 +4964,9 @@ def test_encode_preserves_leading_ws_on_value(self):
         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
index 000000000000..02d0ef891bec
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-05-22-02-25-31.bpo-27737.7bgKpa.rst
@@ -0,0 +1,2 @@
+Allow whitespace only header encoding in ``email.header`` - by Batuhan
+Taskaya



More information about the Python-checkins mailing list