summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>2019-05-23 01:13:16 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2019-05-23 01:13:16 (GMT)
commitef5bb25e2d6147cd44be9c9b166525fb30485be0 (patch)
tree34b3fa59b4861461fab7223207c8605b75e88ec6 /Lib
parent6bc5917903b722bdd0e5d3020949f26fec5dfe9a (diff)
downloadcpython-ef5bb25e2d6147cd44be9c9b166525fb30485be0.zip
cpython-ef5bb25e2d6147cd44be9c9b166525fb30485be0.tar.gz
cpython-ef5bb25e2d6147cd44be9c9b166525fb30485be0.tar.bz2
bpo-27737: Allow whitespace only headers encoding (#13478)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/email/header.py2
-rw-r--r--Lib/test/test_email/test_email.py3
2 files changed, 4 insertions, 1 deletions
diff --git a/Lib/email/header.py b/Lib/email/header.py
index 7b30a03..4ab0032 100644
--- a/Lib/email/header.py
+++ b/Lib/email/header.py
@@ -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))
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 621754c..dfb3be8 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -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