Ticket #11907: 11907.2.diff

File 11907.2.diff, 1.4 KB (added by djansoft, 5 years ago)

Fix with test.

  • django/forms/fields.py

    diff --git a/django/forms/fields.py b/django/forms/fields.py
    index 2e6eb82..4793633 100644
    a b class EmailField(CharField): 
    414414        'invalid': _(u'Enter a valid e-mail address.'),
    415415    }
    416416    default_validators = [validators.validate_email]
     417         
     418    def clean(self, value):
     419        if value is None:
     420            value = u''
     421        value = smart_str(value).strip()
     422        value = super(EmailField, self).clean(value)
     423        return value
    417424
    418425class FileField(Field):
    419426    widget = FileInput
  • tests/regressiontests/forms/fields.py

    diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py
    index 8733090..bff6e70 100644
    a b class FieldsTests(TestCase): 
    425425        self.assertEqual(u'', f.clean(''))
    426426        self.assertEqual(u'', f.clean(None))
    427427        self.assertEqual(u'person@example.com', f.clean('person@example.com'))
     428        self.assertEqual(u'example@example.com', f.clean('      example@example.com  \t   \t '))
    428429        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
    429430        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
    430431        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
Back to Top