bpo-43323: Fix UnicodeEncodeError in the email module (GH-32137)

It was raised if the charset itself contains characters not encodable
in UTF-8 (in particular \udcxx characters representing non-decodable
bytes in the source).
This commit is contained in:
Serhiy Storchaka 2022-04-30 13:17:23 +03:00 committed by GitHub
parent 3483299a24
commit e91dee87ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 6 deletions

View file

@ -781,7 +781,7 @@ class MimeParameters(TokenList):
else:
try:
value = value.decode(charset, 'surrogateescape')
except LookupError:
except (LookupError, UnicodeEncodeError):
# XXX: there should really be a custom defect for
# unknown character set to make it easy to find,
# because otherwise unknown charset is a silent