Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3328136

Browse files
committed
Added tests for SF patch #597593, syntactically invalid Content-Type: headers.
1 parent f36d804 commit 3328136

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

Lib/email/test/test_email.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,12 @@ def test_get_content_subtype_from_message_text_plain_explicit(self):
428428
def test_get_content_maintype_error(self):
429429
msg = Message()
430430
msg['Content-Type'] = 'no-slash-in-this-string'
431-
self.assertRaises(ValueError, msg.get_content_maintype)
431+
self.assertEqual(msg.get_content_maintype(), 'text')
432432

433433
def test_get_content_subtype_error(self):
434434
msg = Message()
435435
msg['Content-Type'] = 'no-slash-in-this-string'
436-
self.assertRaises(ValueError, msg.get_content_subtype)
436+
self.assertEqual(msg.get_content_subtype(), 'plain')
437437

438438

439439

@@ -1007,6 +1007,27 @@ def test_multipart_no_boundary(self):
10071007
finally:
10081008
fp.close()
10091009

1010+
def test_invalid_content_type(self):
1011+
eq = self.assertEqual
1012+
neq = self.ndiffAssertEqual
1013+
msg = Message()
1014+
# RFC 2045, $5.2 says invalid yields text/plain
1015+
msg['Content-Type'] = 'text'
1016+
eq(msg.get_content_maintype(), 'text')
1017+
eq(msg.get_content_subtype(), 'plain')
1018+
eq(msg.get_content_type(), 'text/plain')
1019+
# Clear the old value and try something /really/ invalid
1020+
del msg['content-type']
1021+
msg['Content-Type'] = 'foo'
1022+
eq(msg.get_content_maintype(), 'text')
1023+
eq(msg.get_content_subtype(), 'plain')
1024+
eq(msg.get_content_type(), 'text/plain')
1025+
# Still, make sure that the message is idempotently generated
1026+
s = StringIO()
1027+
g = Generator(s)
1028+
g.flatten(msg)
1029+
neq(s.getvalue(), 'Content-Type: foo\n\n')
1030+
10101031

10111032

10121033
# Test RFC 2047 header encoding and decoding

0 commit comments

Comments
 (0)