summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2002-08-20 14:51:10 (GMT)
committerBarry Warsaw <barry@python.org>2002-08-20 14:51:10 (GMT)
commit3328136e3ccc89da6f042d1e58e2277d71b34855 (patch)
treecd8793321524ce91c5cdc476474384aacfe9323b /Lib
parentf36d804b3b5a73814287535bbc840c3df33d9e2d (diff)
downloadcpython-3328136e3ccc89da6f042d1e58e2277d71b34855.zip
cpython-3328136e3ccc89da6f042d1e58e2277d71b34855.tar.gz
cpython-3328136e3ccc89da6f042d1e58e2277d71b34855.tar.bz2
Added tests for SF patch #597593, syntactically invalid Content-Type: headers.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/email/test/test_email.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index 4c84fe1..2259571 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -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')
@@ -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')
+
# Test RFC 2047 header encoding and decoding