[Python-checkins] python/dist/src/Lib/email/test test_email.py, 1.50.10.6, 1.50.10.7

bwarsaw at users.sourceforge.net bwarsaw at users.sourceforge.net
Fri Apr 29 14:12:05 CEST 2005


Update of /cvsroot/python/python/dist/src/Lib/email/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31703/test

Modified Files:
      Tag: release23-maint
	test_email.py 
Log Message:
get_filename(), get_content_charset(): It's possible that the charset named in
an RFC 2231-style header could be bogus or unknown to Python.  In that case,
we return the the text part of the parameter undecoded.  However, in
get_content_charset(), if that is not ascii, then it is an illegal charset and
so we return failobj.

Test cases and a version bump are included.

Committing this to the Python 2.3 branch because I need to generate an email
2.5.6 release that contains these patches.  I will port these fixes to Python
2.4 and 2.5 for email 3.x.



Index: test_email.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/test/test_email.py,v
retrieving revision 1.50.10.6
retrieving revision 1.50.10.7
diff -u -d -r1.50.10.6 -r1.50.10.7
--- test_email.py	6 Nov 2004 00:13:46 -0000	1.50.10.6
+++ test_email.py	29 Apr 2005 12:12:02 -0000	1.50.10.7
@@ -1,4 +1,4 @@
-# Copyright (C) 2001,2002,2003 Python Software Foundation
+# Copyright (C) 2001-2005 Python Software Foundation
 # email package unit tests
 
 import os
@@ -2758,6 +2758,50 @@
         self.assertEqual(msg.get_content_charset(),
                          'this is even more ***fun*** is it not.pdf')
 
+    def test_rfc2231_bad_encoding_in_filename(self):
+        m = '''\
+Content-Disposition: inline;
+\tfilename*0="bogus'xx'This%20is%20even%20more%20";
+\tfilename*1="%2A%2A%2Afun%2A%2A%2A%20";
+\tfilename*2="is it not.pdf"
+
+'''
+        msg = email.message_from_string(m)
+        self.assertEqual(msg.get_filename(),
+                         'This is even more ***fun*** is it not.pdf')
+
+    def test_rfc2231_bad_encoding_in_charset(self):
+        m = """\
+Content-Type: text/plain; charset*=bogus''utf-8%E2%80%9D
+
+"""
+        msg = email.message_from_string(m)
+        # This should return None because non-ascii characters in the charset
+        # are not allowed.
+        self.assertEqual(msg.get_content_charset(), None)
+
+    def test_rfc2231_bad_character_in_charset(self):
+        m = """\
+Content-Type: text/plain; charset*=ascii''utf-8%E2%80%9D
+
+"""
+        msg = email.message_from_string(m)
+        # This should return None because non-ascii characters in the charset
+        # are not allowed.
+        self.assertEqual(msg.get_content_charset(), None)
+
+    def test_rfc2231_bad_character_in_filename(self):
+        m = '''\
+Content-Disposition: inline;
+\tfilename*0="ascii'xx'This%20is%20even%20more%20";
+\tfilename*1="%2A%2A%2Afun%2A%2A%2A%20";
+\tfilename*2="is it not.pdf%E2"
+
+'''
+        msg = email.message_from_string(m)
+        self.assertEqual(msg.get_filename(),
+                         'This is even more ***fun*** is it not.pdf\xe2')
+
 
 
 def _testclasses():



More information about the Python-checkins mailing list