form: don't break on emails with empty parts in domain (#6796)

This commit is contained in:
Frédéric Péters 2015-03-23 22:14:49 +01:00
parent 4962adb525
commit b6ccb50c2a
2 changed files with 8 additions and 0 deletions

View File

@ -234,6 +234,9 @@ def test_emailwidget():
mock_form_submission(req, widget, {'test': 'foo@localhost@test'})
assert widget.has_error()
widget = EmailWidget('test')
mock_form_submission(req, widget, {'test': 'foo@localhost..localdomain'})
assert widget.has_error()
def test_date_widget():
widget = DateWidget('test')

View File

@ -709,6 +709,11 @@ class EmailWidget(StringWidget):
elif get_cfg('emails', {}).get('check_domain_with_dns', True):
# testing for domain existence
domain = self.value.split('@')[-1]
if [x for x in domain.split('.') if not x]:
# empty parts in domain, ex: @example..net, or
# @.example.net
self.error = _('invalid address domain')
return
if not type(domain) is unicode:
domain = unicode(domain, 'utf-8', 'ignore')
domain = domain.encode('idna')