]> granicus.if.org Git - python/commitdiff
Added tests for SF patch #597593, syntactically invalid Content-Type: headers.
authorBarry Warsaw <barry@python.org>
Tue, 20 Aug 2002 14:51:10 +0000 (14:51 +0000)
committerBarry Warsaw <barry@python.org>
Tue, 20 Aug 2002 14:51:10 +0000 (14:51 +0000)
Lib/email/test/test_email.py

index 4c84fe106add196699ba4f2c585858be8c9c5f0a..225957175dc08693ab5e2487f90576d262b80934 100644 (file)
@@ -428,12 +428,12 @@ class TestMessageAPI(TestEmailBase):
     def test_get_content_maintype_error(self):
         msg = Message()
         msg['Content-Type'] = 'no-slash-in-this-string'
-        self.assertRaises(ValueError, msg.get_content_maintype)
+        self.assertEqual(msg.get_content_maintype(), 'text')
 
     def test_get_content_subtype_error(self):
         msg = Message()
         msg['Content-Type'] = 'no-slash-in-this-string'
-        self.assertRaises(ValueError, msg.get_content_subtype)
+        self.assertEqual(msg.get_content_subtype(), 'plain')
 
 
 \f
@@ -1007,6 +1007,27 @@ class TestNonConformant(TestEmailBase):
         finally:
             fp.close()
 
+    def test_invalid_content_type(self):
+        eq = self.assertEqual
+        neq = self.ndiffAssertEqual
+        msg = Message()
+        # RFC 2045, $5.2 says invalid yields text/plain
+        msg['Content-Type'] = 'text'
+        eq(msg.get_content_maintype(), 'text')
+        eq(msg.get_content_subtype(), 'plain')
+        eq(msg.get_content_type(), 'text/plain')
+        # Clear the old value and try something /really/ invalid
+        del msg['content-type']
+        msg['Content-Type'] = 'foo'
+        eq(msg.get_content_maintype(), 'text')
+        eq(msg.get_content_subtype(), 'plain')
+        eq(msg.get_content_type(), 'text/plain')
+        # Still, make sure that the message is idempotently generated
+        s = StringIO()
+        g = Generator(s)
+        g.flatten(msg)
+        neq(s.getvalue(), 'Content-Type: foo\n\n')
+
 
 \f
 # Test RFC 2047 header encoding and decoding