summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email
diff options
context:
space:
mode:
authorAbhilash Raj <maxking@users.noreply.github.com>2019-06-26 20:13:02 (GMT)
committerBarry Warsaw <barry@python.org>2019-06-26 20:13:02 (GMT)
commit7213df7bbfd85378c6e42e1ac63144d5974bdcf6 (patch)
tree10034147cc523bf1870d95b1d3c21b13bc462c92 /Lib/test/test_email
parent2a7d596f27b2342caf168a03c95ebf3b56e5dbbd (diff)
downloadcpython-7213df7bbfd85378c6e42e1ac63144d5974bdcf6.zip
cpython-7213df7bbfd85378c6e42e1ac63144d5974bdcf6.tar.gz
cpython-7213df7bbfd85378c6e42e1ac63144d5974bdcf6.tar.bz2
bpo-29412: Fix indexError when parsing a header value ending unexpectedly (GH-14387)
* patched string index out of range error in get_word function of _header_value_parser.py and created tests in test__header_value_parser.py for CFWS. * Raise HeaderParseError instead of continuing when parsing a word.
Diffstat (limited to 'Lib/test/test_email')
-rw-r--r--Lib/test/test_email/test__header_value_parser.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py
index 649923f..c4e1a9f 100644
--- a/Lib/test/test_email/test__header_value_parser.py
+++ b/Lib/test/test_email/test__header_value_parser.py
@@ -930,6 +930,12 @@ class TestParser(TestParserMixin, TestEmailBase):
self.assertEqual(word.token_type, 'atom')
self.assertEqual(word[0].token_type, 'cfws')
+ def test_get_word_all_CFWS(self):
+ # bpo-29412: Test that we don't raise IndexError when parsing CFWS only
+ # token.
+ with self.assertRaises(errors.HeaderParseError):
+ parser.get_word('(Recipients list suppressed')
+
def test_get_word_qs_yields_qs(self):
word = self._test_get_x(parser.get_word,
'"bar " (bang) ah', '"bar " (bang) ', 'bar ', [], 'ah')
@@ -2343,6 +2349,17 @@ class TestParser(TestParserMixin, TestEmailBase):
# get_address_list
+ def test_get_address_list_CFWS(self):
+ address_list = self._test_get_x(parser.get_address_list,
+ '(Recipient list suppressed)',
+ '(Recipient list suppressed)',
+ ' ',
+ [errors.ObsoleteHeaderDefect], # no content in address list
+ '')
+ self.assertEqual(address_list.token_type, 'address-list')
+ self.assertEqual(len(address_list.mailboxes), 0)
+ self.assertEqual(address_list.mailboxes, address_list.all_mailboxes)
+
def test_get_address_list_mailboxes_simple(self):
address_list = self._test_get_x(parser.get_address_list,
'dinsdale@example.com',