From d4cf4b29235c2ffe8707b0d16a44fd6228034564 Mon Sep 17 00:00:00 2001 From: Sercan Sahin Date: Thu, 9 May 2024 18:39:11 +0200 Subject: [PATCH] adapter.http: change the limit and cursor check --- basyx/aas/adapter/http.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/basyx/aas/adapter/http.py b/basyx/aas/adapter/http.py index cde58b4ad..179efc5ce 100644 --- a/basyx/aas/adapter/http.py +++ b/basyx/aas/adapter/http.py @@ -584,11 +584,13 @@ def _get_submodel_reference(cls, aas: model.AssetAdministrationShell, submodel_i @classmethod def _get_slice(cls, request: Request, iterator: Iterator[T]) -> Tuple[Iterator[T], int]: - limit = request.args.get('limit', type=int, default=10) - cursor = request.args.get('cursor', type=int, default=0) - limit_str= request.args.get('limit', type=str, default="10") - cursor_str= request.args.get('cursor', type=str, default="0") - if not limit_str.isdigit() or not cursor_str.isdigit(): + limit = request.args.get('limit', default="10") + cursor = request.args.get('cursor', default="0") + try: + limit, cursor = int(limit), int(cursor) + if limit < 0 or cursor < 0: + raise ValueError + except ValueError: raise BadRequest("Cursor and limit must be positive integers!") start_index = cursor end_index = cursor + limit