channel.messages: fix possible bugs in extract_limit

This commit is contained in:
Luna Mendes 2018-11-21 21:03:04 -03:00
parent 4580aed97c
commit 50d177e04d
1 changed files with 4 additions and 3 deletions

View File

@ -16,11 +16,12 @@ log = Logger(__name__)
bp = Blueprint('channel_messages', __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: 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() raise ValueError()
except (TypeError, ValueError): except (TypeError, ValueError):
raise BadRequest('limit not int') raise BadRequest('limit not int')