Fixed #18982 - Caught TypeError in DateField.clean

Thanks gwahl at fusionbox com.
This commit is contained in:
Aymeric Augustin 2012-09-23 13:25:47 +02:00
parent 8599f64e54
commit 3174b5f2f5
2 changed files with 6 additions and 1 deletions

View File

@ -341,7 +341,7 @@ class BaseTemporalField(Field):
for format in self.input_formats:
try:
return self.strptime(value, format)
except ValueError:
except (ValueError, TypeError):
continue
raise ValidationError(self.error_messages['invalid'])

View File

@ -356,6 +356,11 @@ class FieldsTests(SimpleTestCase):
self.assertEqual(datetime.date(2006, 10, 25), f.clean(' 25 October 2006 '))
self.assertRaisesMessage(ValidationError, "'Enter a valid date.'", f.clean, ' ')
def test_datefield_5(self):
# Test null bytes (#18982)
f = DateField()
self.assertRaisesMessage(ValidationError, "'Enter a valid date.'", f.clean, 'a\x00b')
# TimeField ###################################################################
def test_timefield_1(self):