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
This commit is contained in:
Henrik Levkowetz 2017-05-25 14:10:42 +00:00
parent 4d97def715
commit 4afe0b8830
2 changed files with 12 additions and 12 deletions

View file

@ -181,13 +181,13 @@ class SubmissionUploadForm(forms.Form):
author_info = self.xmlroot.findall('front/author')
for author in author_info:
author_dict = dict(
company = author.findtext('organization'),
last_name = author.attrib.get('surname'),
full_name = author.attrib.get('fullname'),
email = author.findtext('address/email'),
company = author.findtext('organization').strip(),
last_name = author.attrib.get('surname').strip(),
full_name = author.attrib.get('fullname').strip(),
email = author.findtext('address/email').strip(),
)
self.author_list.append(author_dict)
line = "%(full_name)s <%(email)s>" % author_dict
line = email.utils.formataddr((author_dict['full_name'], author_dict['email']))
self.authors.append(line)
except forms.ValidationError:
raise

View file

@ -1,5 +1,5 @@
import re
import datetime
import email
from django.db import models
import jsonfield
@ -15,12 +15,12 @@ from ietf.utils.accesstoken import generate_random_key, generate_access_token
def parse_email_line(line):
"""Split line on the form 'Some Name <email@example.com>'"""
m = re.match("([^<]+) <([^>]+)>$", line)
if m:
return dict(name=m.group(1), email=m.group(2))
else:
return dict(name=line, email="")
"""
Split email address into name and email like
email.utils.parseaddr() but return a dictionary
"""
name, addr = email.utils.parseaddr(line) if '@' in line else (line, '')
return dict(name=name, email=addr)
class Submission(models.Model):
state = models.ForeignKey(DraftSubmissionStateName)