Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Improve email address validator regex & add tests re: #82. #94

Merged
merged 2 commits into from

2 participants

@douglatornell

Added test assertions for the 2 invalid email address patterns described in #82.
Changed email address validator to the one proposed in #82 with a minor correction.

@mcdonc mcdonc merged commit cca6b9c into from
@mcdonc
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 13 deletions.
  1. +5 −4 colander/__init__.py
  2. +11 −9 colander/tests/test_colander.py
View
9 colander/__init__.py
@@ -272,10 +272,11 @@ class Email(Regex):
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}$')
if msg is None:
msg = _("Invalid email address")
- super(Email, self).__init__(
- text_('(?i)^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$'), msg=msg)
+ super(Email, self).__init__(email_regex, msg=msg)
class Range(object):
""" Validator which succeeds if the value it is passed is greater
@@ -1708,7 +1709,7 @@ def __init__(self, *arg, **kw):
_add_node_children(self, arg[1:])
else:
self.typ = self.schema_type()
-
+
# bw compat forces us to manufacture a title if one is not supplied
title = kw.get('title', _marker)
if title is _marker:
@@ -1999,7 +2000,7 @@ def __init__(cls, name, bases, clsattrs):
(_SchemaNode,),
{}
)
-
+
class Schema(SchemaNode):
schema_type = Mapping
View
20 colander/tests/test_colander.py
@@ -362,6 +362,8 @@ def test_invalid_emails(self):
self.assertRaises(Invalid, validator, None, 'name@here.comcom')
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')
class TestLength(unittest.TestCase):
def _makeOne(self, min=None, max=None):
@@ -465,7 +467,7 @@ def test_it_success(self):
val = 'http://example.com'
result = self._callFUT(val)
self.assertEqual(result, None)
-
+
def test_it_failure(self):
val = 'not-a-url'
from colander import Invalid
@@ -727,7 +729,7 @@ def test_cstruct_children_cstruct_is_null(self):
node1.children = [node2]
result = typ.cstruct_children(node1, null)
self.assertEqual(result, [null])
-
+
def test_cstruct_children(self):
from colander import null
typ = self._makeOne()
@@ -959,7 +961,7 @@ def test_cstruct_children_cstruct_is_null(self):
node1.children = [node2]
result = typ.cstruct_children(node1, null)
self.assertEqual(result, [null])
-
+
def test_cstruct_children_toomany(self):
typ = self._makeOne()
node1 = DummySchemaNode(typ, name='node1')
@@ -1197,7 +1199,7 @@ def test_cstruct_children_cstruct_is_null(self):
typ = self._makeOne()
result = typ.cstruct_children(None, null)
self.assertEqual(result, SequenceItems([]))
-
+
def test_cstruct_children_cstruct_is_non_null(self):
from colander import SequenceItems
typ = self._makeOne()
@@ -2508,7 +2510,7 @@ class MyNode(colander.SchemaNode):
node = MyNode(missing=5)
result = node.deserialize(colander.null)
self.assertEqual(result, 5)
-
+
def test_method_values_can_rely_on_binding(self):
import colander
class MyNode(colander.SchemaNode):
@@ -2751,14 +2753,14 @@ class Two(One):
id='a2',
)
c = colander.SchemaNode(
- colander.String(),
+ colander.String(),
id='c2',
)
e = colander.SchemaNode(
colander.String(),
id='e2',
)
-
+
class Three(Two):
b = colander.SchemaNode(
colander.Bool(),
@@ -2801,14 +2803,14 @@ class Two(colander.Schema):
id='a2',
)
c = colander.SchemaNode(
- colander.String(),
+ colander.String(),
id='c2',
)
e = colander.SchemaNode(
colander.String(),
id='e2',
)
-
+
class Three(Two, One):
b = colander.SchemaNode(
colander.Bool(),
Something went wrong with that request. Please try again.