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:
parent
2134e7d439
commit
c629d4e956
@ -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'))
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user