Author: adrian
Date: 2010-10-07 10:50:36 -0500 (Thu, 07 Oct 2010)
New Revision: 13997

Modified:
   django/trunk/django/forms/fields.py
   django/trunk/tests/regressiontests/forms/fields.py
Log:
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

Modified: django/trunk/django/forms/fields.py
===================================================================
--- django/trunk/django/forms/fields.py 2010-10-07 15:13:00 UTC (rev 13996)
+++ django/trunk/django/forms/fields.py 2010-10-07 15:50:36 UTC (rev 13997)
@@ -448,6 +448,10 @@
     }
     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 = {

Modified: django/trunk/tests/regressiontests/forms/fields.py
===================================================================
--- django/trunk/tests/regressiontests/forms/fields.py  2010-10-07 15:13:00 UTC 
(rev 13996)
+++ django/trunk/tests/regressiontests/forms/fields.py  2010-10-07 15:50:36 UTC 
(rev 13997)
@@ -430,6 +430,7 @@
         self.assertEqual(u'', f.clean(''))
         self.assertEqual(u'', f.clean(None))
         self.assertEqual(u'[email protected]', f.clean('[email protected]'))
+        self.assertEqual(u'[email protected]', f.clean('      
[email protected]  \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, 'f...@bar')

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to