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):
|
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'))
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue