mirror of https://github.com/django/django.git
Fixed #23924 -- Made EmailMessage raise TypeError for type checks
This commit is contained in:
parent
dd35cc232a
commit
abf87333a1
|
@ -224,17 +224,20 @@ class EmailMessage(object):
|
||||||
necessary encoding conversions.
|
necessary encoding conversions.
|
||||||
"""
|
"""
|
||||||
if to:
|
if to:
|
||||||
assert not isinstance(to, six.string_types), '"to" argument must be a list or tuple'
|
if isinstance(to, six.string_types):
|
||||||
|
raise TypeError('"to" argument must be a list or tuple')
|
||||||
self.to = list(to)
|
self.to = list(to)
|
||||||
else:
|
else:
|
||||||
self.to = []
|
self.to = []
|
||||||
if cc:
|
if cc:
|
||||||
assert not isinstance(cc, six.string_types), '"cc" argument must be a list or tuple'
|
if isinstance(cc, six.string_types):
|
||||||
|
raise TypeError('"cc" argument must be a list or tuple')
|
||||||
self.cc = list(cc)
|
self.cc = list(cc)
|
||||||
else:
|
else:
|
||||||
self.cc = []
|
self.cc = []
|
||||||
if bcc:
|
if bcc:
|
||||||
assert not isinstance(bcc, six.string_types), '"bcc" argument must be a list or tuple'
|
if isinstance(bcc, six.string_types):
|
||||||
|
raise TypeError('"bcc" argument must be a list or tuple')
|
||||||
self.bcc = list(bcc)
|
self.bcc = list(bcc)
|
||||||
else:
|
else:
|
||||||
self.bcc = []
|
self.bcc = []
|
||||||
|
|
|
@ -95,6 +95,14 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
|
||||||
self.assertEqual(message['Cc'], 'cc@example.com, cc.other@example.com')
|
self.assertEqual(message['Cc'], 'cc@example.com, cc.other@example.com')
|
||||||
self.assertEqual(email.recipients(), ['to@example.com', 'other@example.com', 'cc@example.com', 'cc.other@example.com', 'bcc@example.com'])
|
self.assertEqual(email.recipients(), ['to@example.com', 'other@example.com', 'cc@example.com', 'cc.other@example.com', 'bcc@example.com'])
|
||||||
|
|
||||||
|
def test_recipients_as_string(self):
|
||||||
|
with self.assertRaisesMessage(TypeError, '"to" argument must be a list or tuple'):
|
||||||
|
EmailMessage(to='foo@example.com')
|
||||||
|
with self.assertRaisesMessage(TypeError, '"cc" argument must be a list or tuple'):
|
||||||
|
EmailMessage(cc='foo@example.com')
|
||||||
|
with self.assertRaisesMessage(TypeError, '"bcc" argument must be a list or tuple'):
|
||||||
|
EmailMessage(bcc='foo@example.com')
|
||||||
|
|
||||||
def test_header_injection(self):
|
def test_header_injection(self):
|
||||||
email = EmailMessage('Subject\nInjection Test', 'Content', 'from@example.com', ['to@example.com'])
|
email = EmailMessage('Subject\nInjection Test', 'Content', 'from@example.com', ['to@example.com'])
|
||||||
self.assertRaises(BadHeaderError, email.message)
|
self.assertRaises(BadHeaderError, email.message)
|
||||||
|
|
Loading…
Reference in New Issue