diff --git a/gluon/tests/test_validators.py b/gluon/tests/test_validators.py index 502b193d..49c3c2b1 100644 --- a/gluon/tests/test_validators.py +++ b/gluon/tests/test_validators.py @@ -531,6 +531,11 @@ class TestValidators(unittest.TestCase): rtn = IS_EMAIL(error_message='oops')(42) self.assertEqual(rtn, (42, 'oops')) + # test for Internationalized Domain Names, see https://docs.python.org/2/library/codecs.html#module-encodings.idna + rtn = IS_EMAIL()('web2py@Alliancefrançaise.nu') + self.assertEqual(rtn, ('web2py@Alliancefrançaise.nu', None)) + + def test_IS_LIST_OF_EMAILS(self): emails = ['localguy@localhost', '_Yosemite.Sam@example.com'] rtn = IS_LIST_OF_EMAILS()(','.join(emails)) diff --git a/gluon/validators.py b/gluon/validators.py index 0aa1ec37..360cb17f 100644 --- a/gluon/validators.py +++ b/gluon/validators.py @@ -21,7 +21,7 @@ import urllib import struct import decimal import unicodedata -from gluon._compat import StringIO, long, unicodeT, to_unicode, urllib_unquote, unichr, to_bytes, PY2, to_unicode, to_native +from gluon._compat import StringIO, long, basestring, unicodeT, to_unicode, urllib_unquote, unichr, to_bytes, PY2, to_unicode, to_native from gluon.utils import simple_hash, web2py_uuid, DIGEST_ALG_BY_SIZE from pydal.objects import Field, FieldVirtual, FieldMethod from functools import reduce @@ -1156,15 +1156,16 @@ class IS_EMAIL(Validator): """ - regex = re.compile(''' + body_regex = re.compile(''' ^(?!\.) # name may not begin with a dot ( [-a-z0-9!\#$%&'*+/=?^_`{|}~] # all legal characters except dot | (?