fix: assert offset and per_page are positive

Signed-off-by: Leonidas Spyropoulos <artafinde@archlinux.org>
This commit is contained in:
Leonidas Spyropoulos 2023-01-14 11:22:03 +02:00
parent f6c4891415
commit 4d0a982c51
3 changed files with 19 additions and 4 deletions

View file

@ -48,7 +48,7 @@ async def requests(
if not dict(request.query_params).keys() & FILTER_PARAMS:
filter_pending = True
O, PP = util.sanitize_params(O, PP)
O, PP = util.sanitize_params(str(O), str(PP))
context["O"] = O
context["PP"] = PP
context["filter_pending"] = filter_pending

View file

@ -96,14 +96,14 @@ def apply_all(iterable: Iterable, fn: Callable):
return iterable
def sanitize_params(offset: str, per_page: str) -> Tuple[int, int]:
def sanitize_params(offset_str: str, per_page_str: str) -> Tuple[int, int]:
try:
offset = int(offset)
offset = defaults.O if int(offset_str) < 0 else int(offset_str)
except ValueError:
offset = defaults.O
try:
per_page = int(per_page)
per_page = defaults.PP if int(per_page_str) < 0 else int(per_page_str)
except ValueError:
per_page = defaults.PP