Fixed #29389 -- Made Paginator reject non-integer page numbers of type float.

This commit is contained in:
Nicolas Noé 2018-05-09 12:25:39 +02:00 committed by Tim Graham
parent 2134e7d439
commit c629d4e956
2 changed files with 4 additions and 0 deletions

View File

@ -35,6 +35,8 @@ class Paginator:
def validate_number(self, number): def validate_number(self, number):
"""Validate the given 1-based page number.""" """Validate the given 1-based page number."""
try: try:
if isinstance(number, float) and not number.is_integer():
raise ValueError
number = int(number) number = int(number)
except (TypeError, ValueError): except (TypeError, ValueError):
raise PageNotAnInteger(_('That page number is not an integer')) raise PageNotAnInteger(_('That page number is not an integer'))

View File

@ -120,6 +120,8 @@ class PaginationTests(unittest.TestCase):
paginator.validate_number(None) paginator.validate_number(None)
with self.assertRaises(PageNotAnInteger): with self.assertRaises(PageNotAnInteger):
paginator.validate_number('x') paginator.validate_number('x')
with self.assertRaises(PageNotAnInteger):
paginator.validate_number(1.2)
def test_float_integer_page(self): def test_float_integer_page(self):
paginator = Paginator([1, 2, 3], 2) paginator = Paginator([1, 2, 3], 2)