FIX: Negative limit values shouldn't cause error 500 (#10162)

This commit is contained in:
Osama Sayegh 2020-07-02 19:52:37 +03:00 committed by GitHub
parent 2df388ffd7
commit de243426c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -214,6 +214,10 @@ class TagsController < ::ApplicationController
exclude_has_synonyms: params[:excludeHasSynonyms]
}
if filter_params[:limit] && filter_params[:limit].to_i < 0
raise Discourse::InvalidParameters.new(:limit)
end
if params[:categoryId]
filter_params[:category] = Category.find_by_id(params[:categoryId])
end

View File

@ -707,6 +707,13 @@ describe TagsController do
['common1', 'common2', 'group1tag', 'group1tag2']
)
end
it 'returns error 400 for negative limit' do
get "/tags/filter/search.json", params: { q: '', limit: -1 }
expect(response.status).to eq(400)
expect(response.parsed_body['errors'].first).to eq(I18n.t('invalid_params', message: 'limit'))
end
end
end