From 3174b5f2f5bb0b0a6b775a1a50464b6bf2a4b067 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 23 Sep 2012 13:25:47 +0200 Subject: [PATCH] Fixed #18982 - Caught TypeError in DateField.clean Thanks gwahl at fusionbox com. --- django/forms/fields.py | 2 +- tests/regressiontests/forms/tests/fields.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/django/forms/fields.py b/django/forms/fields.py index 124e4f669ad..00753252889 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -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']) diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py index 197ce1abd92..989acbc4963 100644 --- a/tests/regressiontests/forms/tests/fields.py +++ b/tests/regressiontests/forms/tests/fields.py @@ -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):