A platform for community discussion. Free, open, simple.
DEV: raise error if search term length is less than required
Vinoth Kannana313b0114849
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rbindex ad74f595745..76a21ca6bc7 100644--- a/app/controllers/search_controller.rb+++ b/app/controllers/search_controller.rb@@ -9,6 +9,9 @@ class SearchController < ApplicationControllerenddef show+ @search_term = params.require(:q)+ raise Discourse::InvalidParameters.new(:q) if @search_term.length < SiteSetting.min_search_term_length+search_args = {type_filter: 'topic',guardian: guardian,@@ -29,7 +32,6 @@ class SearchController < ApplicationControllersearch_args[:ip_address] = request.remote_ipsearch_args[:user_id] = current_user.id if current_user.present?- @search_term = params[:q]search = Search.new(@search_term, search_args)result = search.executediff --git a/spec/requests/search_controller_spec.rb b/spec/requests/search_controller_spec.rbindex 3f2446c5efc..16ce9261fae 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 "raises an error when the search term length is less than required" do+ get "/search.json", params: { q: 'ba' }+ expect(response.status).to eq(400)+ end+it "logs the search term" doSiteSetting.log_search_queries = trueget "/search.json", params: { q: 'bantha' }