Updated EmailField length to support long domains (#243)

This commit is contained in:
Ross Lawley 2013-04-16 20:46:02 +00:00
parent 3a85422e8f
commit b562e209d1
3 changed files with 18 additions and 3 deletions

View File

@ -4,6 +4,7 @@ Changelog
Changes in 0.7.10 Changes in 0.7.10
================= =================
- Updated EmailField length to support long domains (#243)
- Added 64-bit integer support (#251) - Added 64-bit integer support (#251)
- Added Django sessions TTL support (#224) - Added Django sessions TTL support (#224)
- Fixed issue with numerical keys in MapField(EmbeddedDocumentField()) (#240) - Fixed issue with numerical keys in MapField(EmbeddedDocumentField()) (#240)

View File

@ -143,7 +143,7 @@ class EmailField(StringField):
EMAIL_REGEX = re.compile( EMAIL_REGEX = re.compile(
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE # domain r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,253}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE # domain
) )
def validate(self, value): def validate(self, value):

View File

@ -2371,12 +2371,26 @@ class FieldTest(unittest.TestCase):
self.assertTrue(1 in error_dict['comments']) self.assertTrue(1 in error_dict['comments'])
self.assertTrue('content' in error_dict['comments'][1]) self.assertTrue('content' in error_dict['comments'][1])
self.assertEqual(error_dict['comments'][1]['content'], self.assertEqual(error_dict['comments'][1]['content'],
u'Field is required') u'Field is required')
post.comments[1].content = 'here we go' post.comments[1].content = 'here we go'
post.validate() post.validate()
def test_email_field(self):
class User(Document):
email = EmailField()
user = User(email="ross@example.com")
self.assertTrue(user.validate() is None)
user = User(email=("Kofq@rhom0e4klgauOhpbpNdogawnyIKvQS0wk2mjqrgGQ5S"
"ucictfqpdkK9iS1zeFw8sg7s7cwAF7suIfUfeyueLpfosjn3"
"aJIazqqWkm7.net"))
self.assertTrue(user.validate() is None)
user = User(email='me@localhost')
self.assertRaises(ValidationError, user.validate)
def test_email_field_honors_regex(self): def test_email_field_honors_regex(self):
class User(Document): class User(Document):
email = EmailField(regex=r'\w+@example.com') email = EmailField(regex=r'\w+@example.com')