Skip to content

Commit

Permalink
Fixed django#18982 - Caught TypeError in DateField.clean
Browse files Browse the repository at this point in the history
Thanks gwahl at fusionbox com.
  • Loading branch information
aaugustin committed Sep 23, 2012
1 parent 8599f64 commit 3174b5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def to_python(self, value):
for format in self.input_formats:
try:
return self.strptime(value, format)
except ValueError:
except (ValueError, TypeError):
continue
raise ValidationError(self.error_messages['invalid'])

Expand Down
5 changes: 5 additions & 0 deletions tests/regressiontests/forms/tests/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ def test_datefield_4(self):
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):
Expand Down

0 comments on commit 3174b5f

Please sign in to comment.