bpo-38332: Catch KeyError from unknown cte in encoded-word. (GH-16503)

KeyError should cause a failure in parsing the encoded word and should be caught and raised as a _InvalidEWError instead.
This commit is contained in:
Andrei Troie 2019-10-05 17:19:15 +01:00 committed by Abhilash Raj
parent 3faf826e58
commit 65dcc8a8dc
4 changed files with 18 additions and 1 deletions

View file

@ -89,6 +89,10 @@ class TestParser(TestParserMixin, TestEmailBase):
with self.assertRaises(errors.HeaderParseError):
parser.get_encoded_word('=?abc?=')
def test_get_encoded_word_invalid_cte(self):
with self.assertRaises(errors.HeaderParseError):
parser.get_encoded_word('=?utf-8?X?somevalue?=')
def test_get_encoded_word_valid_ew(self):
self._test_get_x(parser.get_encoded_word,
'=?us-ascii?q?this_is_a_test?= bird',
@ -399,6 +403,14 @@ class TestParser(TestParserMixin, TestEmailBase):
[],
'')
def test_get_unstructured_invalid_ew_cte(self):
self._test_get_x(self._get_unst,
'=?utf-8?X?=somevalue?=',
'=?utf-8?X?=somevalue?=',
'=?utf-8?X?=somevalue?=',
[],
'')
# get_qp_ctext
def test_get_qp_ctext_only(self):