Skip to content

Commit 9d6f06e

Browse files
Review
1 parent 3ac0804 commit 9d6f06e

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

Lib/email/_header_value_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,14 +796,13 @@ def params(self):
796796
value = urllib.parse.unquote(value, encoding='latin-1')
797797
else:
798798
try:
799-
charset = utils._sanitize_charset_name(charset, 'ascii')
800799
value = value.decode(charset, 'surrogateescape')
801800
except (LookupError, UnicodeEncodeError):
802801
# XXX: there should really be a custom defect for
803802
# unknown character set to make it easy to find,
804803
# because otherwise unknown charset is a silent
805804
# failure.
806-
value = value.decode('ascii', 'surrogateescape')
805+
value = value.decode('us-ascii', 'surrogateescape')
807806
if utils._has_surrogates(value):
808807
param.defects.append(errors.UndecodableBytesDefect())
809808
value_parts.append(value)

Lib/email/utils.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,8 @@ def decode_params(params):
446446
new_params.append((name, '"%s"' % value))
447447
return new_params
448448

449-
_SANITIZE_TABLE = str.maketrans({i: None for i in range(128, 65536)})
450-
451-
def _sanitize_charset_name(charset, fallback_charset):
452-
if not charset:
453-
return charset
454-
sanitized = charset.translate(_SANITIZE_TABLE)
455-
return sanitized if sanitized else fallback_charset
456-
457449
def collapse_rfc2231_value(value, errors='replace',
458-
fallback_charset='ascii'):
450+
fallback_charset='us-ascii'):
459451
if not isinstance(value, tuple) or len(value) != 3:
460452
return unquote(value)
461453
# While value comes to us as a unicode string, we need it to be a bytes
@@ -466,7 +458,6 @@ def collapse_rfc2231_value(value, errors='replace',
466458
# Issue 17369: if charset/lang is None, decode_rfc2231 couldn't parse
467459
# the value, so use the fallback_charset.
468460
charset = fallback_charset
469-
charset = _sanitize_charset_name(charset, fallback_charset)
470461
rawbytes = bytes(text, 'raw-unicode-escape')
471462
try:
472463
return str(rawbytes, charset, errors)

Lib/test/test_email/test_email.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5717,7 +5717,10 @@ def test_rfc2231_bad_character_in_encoding(self):
57175717
57185718
"""
57195719
msg = email.message_from_string(m)
5720-
self.assertEqual(msg.get_filename(), 'myfile.txt')
5720+
import warnings
5721+
with warnings.catch_warnings():
5722+
warnings.simplefilter("ignore", DeprecationWarning)
5723+
self.assertEqual(msg.get_filename(), 'myfile.txt')
57215724

57225725
def test_rfc2231_single_tick_in_filename_extended(self):
57235726
eq = self.assertEqual

0 commit comments

Comments
 (0)