Skip to content

Commit

Permalink
fix: handle string values for max suggestions param (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis authored Jun 12, 2023
1 parent cd56484 commit 9d6a739
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/masquerade/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def suggest():

search_text = request.args.get('text')
max_results = request.args.get('maxSuggestions') or DEFAULT_MAX_SUGGESTIONS
if isinstance(max_results, str):
max_results = DEFAULT_MAX_SUGGESTIONS

return {'suggestions': open_sgid.get_suggestions(cleanse_text(search_text), max_results)}

Expand Down
10 changes: 10 additions & 0 deletions tests/test_masquerade.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,13 @@ def test_head_requests(test_client):

assert response.status_code == 200
assert response.headers['Cache-Control']


def test_can_handle_bad_values(test_client):
response = test_client.get(f'{GEOCODE_SERVER_ROUTE}/suggest?text=123&maxSuggestions=undefined')

assert response.status_code == 200

response_json = json.loads(response.data)

assert len(response_json['suggestions']) > 0

0 comments on commit 9d6a739

Please sign in to comment.