From c629d4e9562e7b04b39ca5224af6fd08a3cb14bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20No=C3=A9?= Date: Wed, 9 May 2018 12:25:39 +0200 Subject: [PATCH] Fixed #29389 -- Made Paginator reject non-integer page numbers of type float. --- django/core/paginator.py | 2 ++ tests/pagination/tests.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/django/core/paginator.py b/django/core/paginator.py index bc41ddb914..4af80a26f2 100644 --- a/django/core/paginator.py +++ b/django/core/paginator.py @@ -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')) diff --git a/tests/pagination/tests.py b/tests/pagination/tests.py index 5c2e7db197..8be81240e8 100644 --- a/tests/pagination/tests.py +++ b/tests/pagination/tests.py @@ -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)