FIX: Require q param in /tags/filter/search route (#8263)

* Require q param in /tags/filter/search route.
* If not provided this route was causing a 500 error when
  DiscourseTagging.clean_tag was called, because .downcase
  was being called on the param (which was nil).
* Now return a 400 error instead.
This commit is contained in:
Martin Brennan 2019-10-30 16:32:48 +10:00 committed by GitHub
parent 2ae71b7a87
commit 968a1419df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -193,6 +193,8 @@ class TagsController < ::ApplicationController
end
def search
params.require(:q)
clean_name = DiscourseTagging.clean_tag(params[:q])
category = params[:categoryId] ? Category.find_by_id(params[:categoryId]) : nil

View File

@ -428,6 +428,15 @@ describe TagsController do
json = ::JSON.parse(response.body)
expect(json["results"].map { |j| j["id"] }).to eq(['тема-в-разработке'])
end
context 'when tag query parameter is not provided' do
it 'does not cause a 500 error, returns a param required message' do
get "/tags/filter/search.json", params: {}
expect(response.status).to eq(400)
json = ::JSON.parse(response.body)
expect(json['errors']).to include('param is missing or the value is empty: q')
end
end
end
end