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

@ -1057,7 +1057,7 @@ def get_encoded_word(value):
value = ''.join(remainder)
try:
text, charset, lang, defects = _ew.decode('=?' + tok + '?=')
except ValueError:
except (ValueError, KeyError):
raise _InvalidEwError(
"encoded word format invalid: '{}'".format(ew.cte))
ew.charset = charset