Skip to content

Commit

Permalink
Fixed #11907 -- EmailField now runs strip() on its input. This means …
Browse files Browse the repository at this point in the history
…mistakenly including leading or trailing spaces will not cause a validation error, and clean() will remove those spaces. Thanks, krisneuharth, djansoft and SmileyChris

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13997 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Oct 7, 2010
1 parent edd767d commit bf0947a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions django/forms/fields.py
Expand Up @@ -448,6 +448,10 @@ class EmailField(CharField):
}
default_validators = [validators.validate_email]

def clean(self, value):
value = self.to_python(value).strip()
return super(EmailField, self).clean(value)

class FileField(Field):
widget = ClearableFileInput
default_error_messages = {
Expand Down
1 change: 1 addition & 0 deletions tests/regressiontests/forms/fields.py
Expand Up @@ -430,6 +430,7 @@ def test_emailfield_33(self):
self.assertEqual(u'', f.clean(''))
self.assertEqual(u'', f.clean(None))
self.assertEqual(u'person@example.com', f.clean('person@example.com'))
self.assertEqual(u'example@example.com', f.clean(' example@example.com \t \t '))
self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
Expand Down

0 comments on commit bf0947a

Please sign in to comment.