application controller: fix errors in normalize_search.
Fix exceptions in `normalize_search` on e.g. `https://danbooru.donmai.us/users?search=blah`. Caused when the `search` param is not a hash.
This commit is contained in:
@@ -189,8 +189,8 @@ class ApplicationController < ActionController::Base
|
|||||||
# /tags?search[name]=touhou&search[category]=&search[order]=
|
# /tags?search[name]=touhou&search[category]=&search[order]=
|
||||||
# => /tags?search[name]=touhou
|
# => /tags?search[name]=touhou
|
||||||
def normalize_search
|
def normalize_search
|
||||||
return unless request.get?
|
return unless request.get? && params[:action] == "index"
|
||||||
params[:search] ||= ActionController::Parameters.new
|
params[:search] = search_params
|
||||||
|
|
||||||
deep_reject_blank = lambda do |hash|
|
deep_reject_blank = lambda do |hash|
|
||||||
hash.reject { |k, v| v.blank? || (v.is_a?(Hash) && deep_reject_blank.call(v).blank?) }
|
hash.reject { |k, v| v.blank? || (v.is_a?(Hash) && deep_reject_blank.call(v).blank?) }
|
||||||
@@ -204,7 +204,9 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search_params
|
def search_params
|
||||||
params.fetch(:search, {}).permit!
|
search_params = params.fetch(:search, {})
|
||||||
|
search_params = ActionController::Parameters.new unless search_params.is_a?(ActionController::Parameters)
|
||||||
|
search_params.permit!
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_safe_mode
|
def set_safe_mode
|
||||||
|
|||||||
@@ -35,5 +35,10 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_response 410
|
assert_response 410
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "normalize search params" do
|
||||||
|
get tags_path, params: { search: { name: "bkub", post_count: "" } }
|
||||||
|
assert_redirected_to tags_path(search: { name: "bkub" })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user