Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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 SmileyChris authored
Showing with 5 additions and 0 deletions.
  1. +4 −0 django/forms/fields.py
  2. +1 −0  tests/regressiontests/forms/fields.py
4 django/forms/fields.py
View
@@ -433,6 +433,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 = FileInput
default_error_messages = {
1  tests/regressiontests/forms/fields.py
View
@@ -426,6 +426,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')
Please sign in to comment.
Something went wrong with that request. Please try again.