1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

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):
"""Validate the given 1-based page number."""
try:
if isinstance(number, float) and not number.is_integer():
raise ValueError
number = int(number)
except (TypeError, ValueError):
raise PageNotAnInteger(_('That page number is not an integer'))

View File

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