FIX: raises an error if q param is empty in search page

FIX: raises an error if q param is empty in search page
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 76a21ca..b1fc8b0 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -9,8 +9,8 @@ class SearchController < ApplicationController
   end
 
   def 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_length
 
     search_args = {
       type_filter: 'topic',
diff --git a/spec/requests/search_controller_spec.rb b/spec/requests/search_controller_spec.rb
index 16ce926..ca3e20f 100644
--- a/spec/requests/search_controller_spec.rb
+++ b/spec/requests/search_controller_spec.rb
@@ -127,6 +127,11 @@ describe SearchController do
   end
 
   context "#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" do
       get "/search.json", params: { q: 'ba' }
       expect(response.status).to eq(400)

GitHub
sha: e7e40748

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/search-page-broken/104774/5