From 50d177e04dff4dc5e44df743d385681c09ce38e6 Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Wed, 21 Nov 2018 21:03:04 -0300 Subject: [PATCH] channel.messages: fix possible bugs in extract_limit --- litecord/blueprints/channel/messages.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/litecord/blueprints/channel/messages.py b/litecord/blueprints/channel/messages.py index bf14ed1..5bdd925 100644 --- a/litecord/blueprints/channel/messages.py +++ b/litecord/blueprints/channel/messages.py @@ -16,11 +16,12 @@ log = Logger(__name__) bp = Blueprint('channel_messages', __name__) -def extract_limit(request, default: int = 50): +def extract_limit(request_, default: int = 50, max_val: int = 100): + """Extract a limit kwarg.""" try: - limit = int(request.args.get('limit', default)) + limit = int(request_.args.get('limit', default)) - if limit not in range(0, 100): + if limit not in range(0, max_val + 1): raise ValueError() except (TypeError, ValueError): raise BadRequest('limit not int')