Skip to content

Commit d666e12

Browse files
committed
Fix BadHeaderError when a story name contains newlines
Sentry issue number: PYDOTORG-PROD-24
1 parent 5878911 commit d666e12

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

successstories/models.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ def send_email_to_psf(sender, instance, created, **kwargs):
136136
137137
Review URL: {admin_url}
138138
"""
139+
name_lines = instance.name.splitlines()
140+
name = name_lines[0] if name_lines else instance.name
139141
email = EmailMessage(
140-
'New success story submission: {}'.format(instance.name),
142+
'New success story submission: {}'.format(name),
141143
body.format(
142144
name=instance.name,
143145
company_name=instance.company_name,

successstories/tests/test_views.py

+30
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,33 @@ def test_story_create(self):
120120
self.assertContains(response, 'Please use a unique name.')
121121

122122
del mail.outbox[:]
123+
124+
def test_story_multiline_email_subject(self):
125+
mail.outbox = []
126+
127+
url = reverse('success_story_create')
128+
129+
post_data = {
130+
'name': 'First line\nSecond line',
131+
'company_name': 'Company Three',
132+
'company_url': 'http://djangopony.com/',
133+
'category': self.category.pk,
134+
'author': 'Kevin Arnold',
135+
'author_email': '[email protected]',
136+
'pull_quote': 'Liver!',
137+
'content': 'Growing up is never easy.\n\nFoo bar baz.\n',
138+
settings.HONEYPOT_FIELD_NAME: settings.HONEYPOT_VALUE,
139+
}
140+
141+
response = self.client.post(url, post_data)
142+
self.assertEqual(response.status_code, 302)
143+
self.assertRedirects(response, url)
144+
145+
self.assertEqual(len(mail.outbox), 1)
146+
self.assertEqual(
147+
mail.outbox[0].subject,
148+
'New success story submission: First line'
149+
)
150+
self.assertNotIn('Second line', mail.outbox[0].subject)
151+
152+
del mail.outbox[:]

0 commit comments

Comments
 (0)