From b6ccb50c2ad347b5a3cdfdad901fb4d21bf969c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 23 Mar 2015 22:14:49 +0100 Subject: [PATCH] form: don't break on emails with empty parts in domain (#6796) --- tests/test_widgets.py | 3 +++ wcs/qommon/form.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 06bf537..599bce7 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -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') diff --git a/wcs/qommon/form.py b/wcs/qommon/form.py index 7904f29..02de720 100644 --- a/wcs/qommon/form.py +++ b/wcs/qommon/form.py @@ -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') -- 2.1.4