summaryrefslogtreecommitdiff
path: root/Lib/email
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-12-27 19:17:17 +0000
committerR. David Murray <rdmurray@bitdance.com>2010-12-27 19:17:17 +0000
commit5360d003b666f874a05dd532ecf511cd459117f8 (patch)
tree69e97598af1065dc4ed850d103e67e6bc2b6872d /Lib/email
parent49ee82c4eb18003a198a6fc02f2bbbcb5d931180 (diff)
downloadcpython-git-5360d003b666f874a05dd532ecf511cd459117f8.tar.gz
#1379416: encode charset name to ascii to avoid unicode promotion of output
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/charset.py2
-rw-r--r--Lib/email/test/test_email.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/Lib/email/charset.py b/Lib/email/charset.py
index ad56c58f80..dddaa76c55 100644
--- a/Lib/email/charset.py
+++ b/Lib/email/charset.py
@@ -209,7 +209,7 @@ class Charset:
input_charset = unicode(input_charset, 'ascii')
except UnicodeError:
raise errors.CharsetError(input_charset)
- input_charset = input_charset.lower()
+ input_charset = input_charset.lower().encode('ascii')
# Set the input charset after filtering through the aliases and/or codecs
if not (input_charset in ALIASES or input_charset in CHARSETS):
try:
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index 358b6a7ef0..4aac500ce8 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -3140,6 +3140,13 @@ A very long line that must get split to something other than at the
'attachment; filename*="iso-8859-1\'\'Fu%DFballer.ppt"',
msg['Content-Disposition'])
+ def test_encode_unaliased_charset(self):
+ # Issue 1379416: when the charset has no output conversion,
+ # output was accidentally getting coerced to unicode.
+ res = Header('abc','iso-8859-2').encode()
+ self.assertEqual(res, '=?iso-8859-2?q?abc?=')
+ self.assertIsInstance(res, str)
+
# Test RFC 2231 header parameters (en/de)coding
class TestRFC2231(TestEmailBase):