Fixed #26890 -- Fixed IntegerField crash on Unicode numbers.

This commit is contained in:
Jon Dufresne 2016-07-14 06:38:57 -07:00 committed by Tim Graham
parent 944e66cb1d
commit 76e19da5b0
2 changed files with 5 additions and 1 deletions

View File

@ -276,7 +276,7 @@ class IntegerField(Field):
value = formats.sanitize_separators(value)
# Strip trailing decimal and zeros.
try:
value = int(self.re_decimal.sub('', str(value)))
value = int(self.re_decimal.sub('', force_text(value)))
except (ValueError, TypeError):
raise ValidationError(self.error_messages['invalid'], code='invalid')
return value

View File

@ -123,6 +123,10 @@ class IntegerFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
self.assertEqual(9223372036854775808, f.clean('9223372036854775808'))
self.assertEqual(9223372036854775808, f.clean('9223372036854775808.0'))
def test_integerfield_unicode_number(self):
f = IntegerField()
self.assertEqual(50, f.clean(''))
def test_integerfield_subclass(self):
"""
Class-defined widget is not overwritten by __init__() (#22245).