- Loosen Email validator regex (permit apostrophes, bang, etc in localpart).
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| Next release | ||||
| ------------ | ||||
|  | ||||
| - .... | ||||
| - Loosen Email validator regex (permit apostrophes, bang, etc in localpart). | ||||
|  | ||||
| 1.0a3 (2013-05-16) | ||||
| ------------------ | ||||
|   | ||||
| @@ -275,14 +275,16 @@ class Regex(object): | ||||
|         if self.match_object.match(value) is None: | ||||
|             raise Invalid(node, self.msg) | ||||
|  | ||||
| EMAIL_RE = "(?i)^[A-Z0-9._%!#$%&'*+-/=?^_`{|}~()]+@[A-Z0-9]+([.-][A-Z0-9]+)*\.[A-Z]{2,8}$" | ||||
|  | ||||
| class Email(Regex): | ||||
|     """ Email address validator. If ``msg`` is supplied, it will be | ||||
|         the error message to be used when raising :exc:`colander.Invalid`; | ||||
|         otherwise, defaults to 'Invalid email address'. | ||||
|     """ | ||||
|      | ||||
|     def __init__(self, msg=None): | ||||
|         email_regex = text_( | ||||
|             '(?i)^[A-Z0-9._%+-]+@[A-Z0-9]+([.-][A-Z0-9]+)*\.[A-Z]{2,4}$') | ||||
|         email_regex = text_(EMAIL_RE) | ||||
|         if msg is None: | ||||
|             msg = _("Invalid email address") | ||||
|         super(Email, self).__init__(email_regex, msg=msg) | ||||
|   | ||||
| @@ -349,6 +349,7 @@ class TestEmail(unittest.TestCase): | ||||
|         self.assertEqual(validator(None, 'name@here1.us'), None) | ||||
|         self.assertEqual(validator(None, 'name@here1.info'), None) | ||||
|         self.assertEqual(validator(None, 'foo@bar.baz.biz'), None) | ||||
|         self.assertEqual(validator(None, "tip'oneill@house.gov"), None) | ||||
|  | ||||
|     def test_empty_email(self): | ||||
|         validator = self._makeOne() | ||||
| @@ -359,9 +360,8 @@ class TestEmail(unittest.TestCase): | ||||
|         validator = self._makeOne() | ||||
|         from colander import Invalid | ||||
|         self.assertRaises(Invalid, validator, None, 'me@here.') | ||||
|         self.assertRaises(Invalid, validator, None, 'name@here.comcom') | ||||
|         self.assertRaises(Invalid, validator, None, 'name@here.tldiswaytoolong') | ||||
|         self.assertRaises(Invalid, validator, None, '@here.us') | ||||
|         self.assertRaises(Invalid, validator, None, '(name)@here.info') | ||||
|         self.assertRaises(Invalid, validator, None, 'me@here..com') | ||||
|         self.assertRaises(Invalid, validator, None, 'me@we-here-.com') | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Chris McDonough
					Chris McDonough