Skip to content

Commit 3029598

Browse files
authored
Fix index error for empty sortby parameter (#2185)
1 parent e381c93 commit 3029598

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pygeoapi/api/itemtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,12 @@ def get_collection_items(
431431
for s in sorts:
432432
prop = s
433433
order = '+'
434-
if s[0] in ['+', '-']:
434+
if s and s[0] in ['+', '-']:
435435
order = s[0]
436436
prop = s[1:]
437437

438438
if prop not in p.fields.keys():
439-
msg = 'bad sort property'
439+
msg = 'bad sortby property'
440440
return api.get_exception(
441441
HTTPStatus.BAD_REQUEST, headers, request.format,
442442
'InvalidParameterValue', msg)

tests/api/test_itemtypes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
# Authors: Tom Kralidis <[email protected]>
44
# John A Stevenson <[email protected]>
55
# Colin Blackburn <[email protected]>
6+
# Francesco Bartoli <[email protected]>
67
#
78
# Copyright (c) 2025 Tom Kralidis
89
# Copyright (c) 2022 John A Stevenson and Colin Blackburn
10+
# Copyright (c) 2025 Francesco Bartoli
911
#
1012
# Permission is hereby granted, free of charge, to any person
1113
# obtaining a copy of this software and associated documentation
@@ -285,6 +287,13 @@ def test_get_collection_items(config, api_):
285287
assert links[4]['rel'] == 'next'
286288
assert links[5]['rel'] == 'collection'
287289

290+
req = mock_api_request({
291+
'sortby': ''
292+
})
293+
rsp_headers, code, response = get_collection_items(api_, req, 'obs')
294+
295+
assert code == HTTPStatus.BAD_REQUEST
296+
288297
req = mock_api_request({
289298
'sortby': 'bad-property',
290299
'stn_id': '35'

0 commit comments

Comments
 (0)