Skip to content

Commit 4afe0b8

Browse files
committed
Added stripping of leading and trailing whitespace from submission data (including email addresses) gleaned from submitted xml. Changed email line parsing to use email.utils.parseaddr() instead of a regex which only would handle unwuoted names (and possibly not utf-8 names) correctly.
- Legacy-Id: 13423
1 parent 4d97def commit 4afe0b8

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

ietf/submit/forms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ def clean(self):
181181
author_info = self.xmlroot.findall('front/author')
182182
for author in author_info:
183183
author_dict = dict(
184-
company = author.findtext('organization'),
185-
last_name = author.attrib.get('surname'),
186-
full_name = author.attrib.get('fullname'),
187-
email = author.findtext('address/email'),
184+
company = author.findtext('organization').strip(),
185+
last_name = author.attrib.get('surname').strip(),
186+
full_name = author.attrib.get('fullname').strip(),
187+
email = author.findtext('address/email').strip(),
188188
)
189189
self.author_list.append(author_dict)
190-
line = "%(full_name)s <%(email)s>" % author_dict
190+
line = email.utils.formataddr((author_dict['full_name'], author_dict['email']))
191191
self.authors.append(line)
192192
except forms.ValidationError:
193193
raise

ietf/submit/models.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import re
21
import datetime
2+
import email
33

44
from django.db import models
55
import jsonfield
@@ -15,12 +15,12 @@
1515

1616

1717
def parse_email_line(line):
18-
"""Split line on the form 'Some Name <email@example.com>'"""
19-
m = re.match("([^<]+) <([^>]+)>$", line)
20-
if m:
21-
return dict(name=m.group(1), email=m.group(2))
22-
else:
23-
return dict(name=line, email="")
18+
"""
19+
Split email address into name and email like
20+
email.utils.parseaddr() but return a dictionary
21+
"""
22+
name, addr = email.utils.parseaddr(line) if '@' in line else (line, '')
23+
return dict(name=name, email=addr)
2424

2525
class Submission(models.Model):
2626
state = models.ForeignKey(DraftSubmissionStateName)

0 commit comments

Comments
 (0)