summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Beaven <smileychris@gmail.com>2010-10-10 10:02:18 +0000
committerChris Beaven <smileychris@gmail.com>2010-10-10 10:02:18 +0000
commitfee4aa31d7c8b08b58dab46c502e3c736d845539 (patch)
tree4ef20fd5ccef012c6557bfcb017e9c38e7ed0f40
parentbe190d1913b3e95cf13bc99d7674facfcfaec41c (diff)
[1.2.X] 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 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
-rw-r--r--django/forms/fields.py4
-rw-r--r--tests/regressiontests/forms/fields.py1
2 files changed, 5 insertions, 0 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index de14a5c8a8..25ba5f5bdd 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -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 = {
diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py
index e4f2c261c9..258d644ff0 100644
--- a/tests/regressiontests/forms/fields.py
+++ b/tests/regressiontests/forms/fields.py
@@ -426,6 +426,7 @@ class FieldsTests(TestCase):
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')