diff --git a/pygeoapi/api/itemtypes.py b/pygeoapi/api/itemtypes.py index fae5f15d7..2810e7f09 100644 --- a/pygeoapi/api/itemtypes.py +++ b/pygeoapi/api/itemtypes.py @@ -431,12 +431,12 @@ def get_collection_items( for s in sorts: prop = s order = '+' - if s[0] in ['+', '-']: + if s and s[0] in ['+', '-']: order = s[0] prop = s[1:] if prop not in p.fields.keys(): - msg = 'bad sort property' + msg = 'bad sortby property' return api.get_exception( HTTPStatus.BAD_REQUEST, headers, request.format, 'InvalidParameterValue', msg) diff --git a/tests/api/test_itemtypes.py b/tests/api/test_itemtypes.py index a601a5259..5a1762151 100644 --- a/tests/api/test_itemtypes.py +++ b/tests/api/test_itemtypes.py @@ -3,9 +3,11 @@ # Authors: Tom Kralidis # John A Stevenson # Colin Blackburn +# Francesco Bartoli # # Copyright (c) 2025 Tom Kralidis # Copyright (c) 2022 John A Stevenson and Colin Blackburn +# Copyright (c) 2025 Francesco Bartoli # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation @@ -285,6 +287,13 @@ def test_get_collection_items(config, api_): assert links[4]['rel'] == 'next' assert links[5]['rel'] == 'collection' + req = mock_api_request({ + 'sortby': '' + }) + rsp_headers, code, response = get_collection_items(api_, req, 'obs') + + assert code == HTTPStatus.BAD_REQUEST + req = mock_api_request({ 'sortby': 'bad-property', 'stn_id': '35'