From acb804e55290f9d3dda459fcfb7820f9e3fcbb6c Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 14 Jul 2016 06:38:57 -0700 Subject: [PATCH] [1.10.x] Fixed #26890 -- Fixed IntegerField crash on Unicode numbers. Backport of 76e19da5b0385d4f8afda509e0b60f77f7ffc4c2 from master --- django/forms/fields.py | 2 +- tests/forms_tests/field_tests/test_integerfield.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/django/forms/fields.py b/django/forms/fields.py index c50cd164ed..8a534e7bb5 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -275,7 +275,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 diff --git a/tests/forms_tests/field_tests/test_integerfield.py b/tests/forms_tests/field_tests/test_integerfield.py index d5c14857ed..cd648279a6 100644 --- a/tests/forms_tests/field_tests/test_integerfield.py +++ b/tests/forms_tests/field_tests/test_integerfield.py @@ -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('50')) + def test_integerfield_subclass(self): """ Class-defined widget is not overwritten by __init__() (#22245).