[1.10.x] Fixed #26890 -- Fixed IntegerField crash on Unicode numbers.
Backport of 76e19da5b0
from master
This commit is contained in:
parent
5c56ce7a3f
commit
acb804e552
|
@ -275,7 +275,7 @@ class IntegerField(Field):
|
||||||
value = formats.sanitize_separators(value)
|
value = formats.sanitize_separators(value)
|
||||||
# Strip trailing decimal and zeros.
|
# Strip trailing decimal and zeros.
|
||||||
try:
|
try:
|
||||||
value = int(self.re_decimal.sub('', str(value)))
|
value = int(self.re_decimal.sub('', force_text(value)))
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
raise ValidationError(self.error_messages['invalid'], code='invalid')
|
raise ValidationError(self.error_messages['invalid'], code='invalid')
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -123,6 +123,10 @@ class IntegerFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
|
||||||
self.assertEqual(9223372036854775808, f.clean('9223372036854775808'))
|
self.assertEqual(9223372036854775808, f.clean('9223372036854775808'))
|
||||||
self.assertEqual(9223372036854775808, f.clean('9223372036854775808.0'))
|
self.assertEqual(9223372036854775808, f.clean('9223372036854775808.0'))
|
||||||
|
|
||||||
|
def test_integerfield_unicode_number(self):
|
||||||
|
f = IntegerField()
|
||||||
|
self.assertEqual(50, f.clean('50'))
|
||||||
|
|
||||||
def test_integerfield_subclass(self):
|
def test_integerfield_subclass(self):
|
||||||
"""
|
"""
|
||||||
Class-defined widget is not overwritten by __init__() (#22245).
|
Class-defined widget is not overwritten by __init__() (#22245).
|
||||||
|
|
Loading…
Reference in New Issue