Commit 01f0f69c authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

packages: fix negative and invalid limit in search API

Resolve 500 issues when limit=wji or limit=-1 by setting a min_value of
0 and changing the field to a IntegerField.
parent 4b93ee3d
......@@ -17,7 +17,7 @@
class PackageSearchForm(forms.Form):
limit = forms.CharField(required=False)
limit = forms.IntegerField(required=False, min_value=0)
page = forms.CharField(required=False)
repo = forms.MultipleChoiceField(required=False)
arch = forms.MultipleChoiceField(required=False)
......@@ -163,8 +163,8 @@ def search_json(request):
form = PackageSearchForm(data=request.GET,
if form.is_valid():
form_limit = form.cleaned_data['limit']
limit = min(limit, int(form_limit)) if form_limit else limit
form_limit = form.cleaned_data.get('limit', limit)
limit = min(limit, form_limit) if form_limit else limit
container['limit'] = limit
packages = Package.objects.select_related('arch', 'repo',
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment