Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11907 -- EmailField now runs strip() on its input. This means …

…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...
commit bf0947a4743ce7df748f6e78a3d6e7d9e4f6cf5d 1 parent edd767d
Adrian Holovaty authored October 07, 2010
4  django/forms/fields.py
@@ -448,6 +448,10 @@ class EmailField(CharField):
448 448
     }
449 449
     default_validators = [validators.validate_email]
450 450
 
  451
+    def clean(self, value):
  452
+        value = self.to_python(value).strip()
  453
+        return super(EmailField, self).clean(value)
  454
+
451 455
 class FileField(Field):
452 456
     widget = ClearableFileInput
453 457
     default_error_messages = {
1  tests/regressiontests/forms/fields.py
@@ -430,6 +430,7 @@ def test_emailfield_33(self):
430 430
         self.assertEqual(u'', f.clean(''))
431 431
         self.assertEqual(u'', f.clean(None))
432 432
         self.assertEqual(u'person@example.com', f.clean('person@example.com'))
  433
+        self.assertEqual(u'example@example.com', f.clean('      example@example.com  \t   \t '))
433 434
         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
434 435
         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
435 436
         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')

0 notes on commit bf0947a

Please sign in to comment.
Something went wrong with that request. Please try again.