[Python-checkins] r87515 - in python/branches/release27-maint: Lib/email/charset.py Lib/email/test/test_email.py Misc/NEWS

r.david.murray python-checkins at python.org
Mon Dec 27 20:17:17 CET 2010


Author: r.david.murray
Date: Mon Dec 27 20:17:17 2010
New Revision: 87515

Log:
#1379416: encode charset name to ascii to avoid unicode promotion of output


Modified:
   python/branches/release27-maint/Lib/email/charset.py
   python/branches/release27-maint/Lib/email/test/test_email.py
   python/branches/release27-maint/Misc/NEWS

Modified: python/branches/release27-maint/Lib/email/charset.py
==============================================================================
--- python/branches/release27-maint/Lib/email/charset.py	(original)
+++ python/branches/release27-maint/Lib/email/charset.py	Mon Dec 27 20:17:17 2010
@@ -209,7 +209,7 @@
                 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:

Modified: python/branches/release27-maint/Lib/email/test/test_email.py
==============================================================================
--- python/branches/release27-maint/Lib/email/test/test_email.py	(original)
+++ python/branches/release27-maint/Lib/email/test/test_email.py	Mon Dec 27 20:17:17 2010
@@ -3140,6 +3140,13 @@
             '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):

Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Mon Dec 27 20:17:17 2010
@@ -22,6 +22,9 @@
 Library
 -------
 
+- Issue #1379416: eliminated a source of accidental unicode promotion in
+  email.header.Header.encode.
+
 - Issue #5258/#10642: if site.py encounters a .pth file that generates an error,
   it now prints the filename, line number, and traceback to stderr and skips
   the rest of that individual file, instead of stopping processing entirely.


More information about the Python-checkins mailing list