diff --git a/src/accounting/utils/pagination.py b/src/accounting/utils/pagination.py index ef769fb..5c4afbc 100644 --- a/src/accounting/utils/pagination.py +++ b/src/accounting/utils/pagination.py @@ -115,9 +115,12 @@ class Pagination(t.Generic[T]): if "page-size" not in request.args: return self.DEFAULT_PAGE_SIZE try: - return int(request.args["page-size"]) + page_size: int = int(request.args["page-size"]) except ValueError: raise Redirection(self.__uri_set("page-size", None)) + if page_size == self.DEFAULT_PAGE_SIZE: + raise Redirection(self.__uri_set("page-size", None)) + return page_size def __set_list(self) -> None: """Sets the items to show in the list. @@ -149,6 +152,8 @@ class Pagination(t.Generic[T]): page_no: int = int(request.args["page-no"]) except ValueError: raise Redirection(self.__uri_set("page-no", None)) + if page_no == self.__default_page_no: + raise Redirection(self.__uri_set("page-no", None)) if page_no < 1: if not self.__is_reversed: raise Redirection(self.__uri_set("page-no", None)) diff --git a/tests/test_utils.py b/tests/test_utils.py index 69c431e..3058339 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -271,9 +271,21 @@ class PaginationTestCase(unittest.TestCase): # A malformed page size self.__test_malformed("q=word&page-size=100a&page-no=37&next=%2F", range(1, 691), "q=word&page-no=37&next=%2F") + # A default page size + self.__test_malformed("q=word" + f"&page-size={Pagination.DEFAULT_PAGE_SIZE}" + "&page-no=37&next=%2F", + range(1, 691), "q=word&page-no=37&next=%2F") # A malformed page number self.__test_malformed("q=word&page-size=15&page-no=37a&next=%2F", range(1, 691), "q=word&page-size=15&next=%2F") + # A default page number + self.__test_malformed("q=word&page-size=15&page-no=1&next=%2F", + range(1, 691), "q=word&page-size=15&next=%2F") + # A default page number, on a reversed list + self.__test_malformed("q=word&page-size=15&page-no=46&next=%2F", + range(1, 691), "q=word&page-size=15&next=%2F", + is_reversed=True) # A page number beyond the last page self.__test_malformed("q=word&page-size=15&page-no=100&next=%2F", range(1, 691),