Fix nested blank search params not being stripped from searches.
From https://danbooru.donmai.us/forum_topics/9127?page=258#forum_post_151308: When you do a user search (from https://danbooru.donmai.us/users/search) the results only include those with someone in the inviter field. The bug was that nested blank search params (/users?search[inviter][name_matches]=) didn't get stripped from the search.
This commit is contained in:
@@ -199,15 +199,17 @@ class ApplicationController < ActionController::Base
|
||||
# /tags?search[name]=touhou&search[category]=&search[order]=
|
||||
# => /tags?search[name]=touhou
|
||||
def normalize_search
|
||||
if request.get?
|
||||
if params[:search].blank?
|
||||
params[:search] = ActionController::Parameters.new
|
||||
end
|
||||
return unless request.get?
|
||||
params[:search] ||= ActionController::Parameters.new
|
||||
|
||||
if params[:search].is_a?(ActionController::Parameters) && params[:search].values.any?(&:blank?)
|
||||
params[:search].reject! {|k,v| v.blank?}
|
||||
redirect_to url_for(params: params.except(:controller, :action, :index).permit!)
|
||||
end
|
||||
deep_reject_blank = lambda do |hash|
|
||||
hash.reject { |k, v| v.blank? || (v.is_a?(Hash) && deep_reject_blank.call(v).blank?) }
|
||||
end
|
||||
nonblank_search_params = deep_reject_blank.call(params[:search])
|
||||
|
||||
if nonblank_search_params != params[:search]
|
||||
params[:search] = nonblank_search_params
|
||||
redirect_to url_for(params: params.except(:controller, :action, :index).permit!)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -26,6 +26,11 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
get users_path, params: {:search => {:name_matches => @user.name}}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "list all users (with blank search parameters)" do
|
||||
get users_path, params: { search: { inviter: { name_matches: "" }, level: "", name: "test" } }
|
||||
assert_redirected_to users_path(search: { name: "test" })
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
|
||||
Reference in New Issue
Block a user