Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #11907 -- EmailField now runs strip() on its input. Thi…

…s means mistakenly including leading or trailing spaces will not cause a validation error, and clean() will remove those spaces. Thanks, krisneuharth and djansoft. Backport of [13997].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14124 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fee4aa31d7c8b08b58dab46c502e3c736d845539 1 parent be190d1
Chris Beaven authored October 10, 2010
4  django/forms/fields.py
@@ -433,6 +433,10 @@ class EmailField(CharField):
433 433
     }
434 434
     default_validators = [validators.validate_email]
435 435
 
  436
+    def clean(self, value):
  437
+        value = self.to_python(value).strip()
  438
+        return super(EmailField, self).clean(value)
  439
+
436 440
 class FileField(Field):
437 441
     widget = FileInput
438 442
     default_error_messages = {
1  tests/regressiontests/forms/fields.py
@@ -426,6 +426,7 @@ def test_emailfield_33(self):
426 426
         self.assertEqual(u'', f.clean(''))
427 427
         self.assertEqual(u'', f.clean(None))
428 428
         self.assertEqual(u'person@example.com', f.clean('person@example.com'))
  429
+        self.assertEqual(u'example@example.com', f.clean('      example@example.com  \t   \t '))
429 430
         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
430 431
         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
431 432
         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')

0 notes on commit fee4aa3

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