summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2011-03-23 19:27:04 (GMT)
committerR David Murray <rdmurray@bitdance.com>2011-03-23 19:27:04 (GMT)
commit523b41c4b3fe79455fc9d1762056ca3e83972aa1 (patch)
treed232d85273344f7c01bdeb31044ea0e404229cca /Lib/email
parent3d9e973abd3fe409545aca18eabfd91fd1001a65 (diff)
parentcafd79d904d19e90af375dbee43668f7dbf733d0 (diff)
downloadcpython-523b41c4b3fe79455fc9d1762056ca3e83972aa1.zip
cpython-523b41c4b3fe79455fc9d1762056ca3e83972aa1.tar.gz
cpython-523b41c4b3fe79455fc9d1762056ca3e83972aa1.tar.bz2
Merge #11590: fix quoprimime decode handling of empty strings and line endings.
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/quoprimime.py6
-rw-r--r--Lib/email/test/test_email.py15
2 files changed, 18 insertions, 3 deletions
diff --git a/Lib/email/quoprimime.py b/Lib/email/quoprimime.py
index 168dfff..bffad4e 100644
--- a/Lib/email/quoprimime.py
+++ b/Lib/email/quoprimime.py
@@ -135,9 +135,9 @@ def header_encode(header_bytes, charset='iso-8859-1'):
charset names the character set to use in the RFC 2046 header. It
defaults to iso-8859-1.
"""
- # Return empty headers unchanged
+ # Return empty headers as an empty string.
if not header_bytes:
- return str(header_bytes)
+ return ''
# Iterate over every byte, encoding if necessary.
encoded = []
for octet in header_bytes:
@@ -268,7 +268,7 @@ def decode(encoded, eol=NL):
if i == n:
decoded += eol
# Special case if original string did not end with eol
- if not encoded.endswith(eol) and decoded.endswith(eol):
+ if encoded[-1] not in '\r\n' and decoded.endswith(eol):
decoded = decoded[:-1]
return decoded
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index 9bbbc87..2ff2a8f 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -3344,6 +3344,9 @@ class TestQuopri(unittest.TestCase):
encoded_header = quoprimime.header_encode(header, charset)
self.assertEqual(encoded_header, expected_encoded_header)
+ def test_header_encode_null(self):
+ self._test_header_encode(b'', '')
+
def test_header_encode_one_word(self):
self._test_header_encode(b'hello', '=?iso-8859-1?q?hello?=')
@@ -3400,6 +3403,15 @@ class TestQuopri(unittest.TestCase):
def test_decode_one_line_lf(self):
self._test_decode('hello\n', 'hello\n')
+ def test_decode_one_line_cr(self):
+ self._test_decode('hello\r', 'hello\n')
+
+ def test_decode_one_line_nl(self):
+ self._test_decode('hello\n', 'helloX', eol='X')
+
+ def test_decode_one_line_crnl(self):
+ self._test_decode('hello\r\n', 'helloX', eol='X')
+
def test_decode_one_line_one_word(self):
self._test_decode('hello\r\nworld', 'hello\nworld')
@@ -3409,6 +3421,9 @@ class TestQuopri(unittest.TestCase):
def test_decode_two_lines(self):
self._test_decode('hello\r\nworld\r\n', 'hello\nworld\n')
+ def test_decode_two_lines_eol(self):
+ self._test_decode('hello\r\nworld\r\n', 'helloXworldX', eol='X')
+
def test_decode_one_long_line(self):
self._test_decode('Spam' * 250, 'Spam' * 250)