A platform for community discussion. Free, open, simple.
FIX: raises an error if q param is empty in search page
Vinoth Kannane7e4074856c7
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rbindex 76a21ca6bc7..b1fc8b0f5a2 100644--- a/app/controllers/search_controller.rb+++ b/app/controllers/search_controller.rb@@ -9,8 +9,8 @@ class SearchController < ApplicationControllerenddef show- @search_term = params.require(:q)- raise Discourse::InvalidParameters.new(:q) if @search_term.length < SiteSetting.min_search_term_length+ @search_term = params[:q]+ raise Discourse::InvalidParameters.new(:q) if @search_term.present? && @search_term.length < SiteSetting.min_search_term_lengthsearch_args = {type_filter: 'topic',diff --git a/spec/requests/search_controller_spec.rb b/spec/requests/search_controller_spec.rbindex 16ce9261fae..ca3e20fa848 100644--- a/spec/requests/search_controller_spec.rb+++ b/spec/requests/search_controller_spec.rb@@ -127,6 +127,11 @@ describe SearchController doendcontext "#show" do+ it "doesn't raise an error when search term not specified" do+ get "/search"+ expect(response.status).to eq(200)+ end+it "raises an error when the search term length is less than required" doget "/search.json", params: { q: 'ba' }expect(response.status).to eq(400)