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&search[category]=&search[order]=
|
||||||
# => /tags?search[name]=touhou
|
# => /tags?search[name]=touhou
|
||||||
def normalize_search
|
def normalize_search
|
||||||
if request.get?
|
return unless request.get?
|
||||||
if params[:search].blank?
|
params[:search] ||= ActionController::Parameters.new
|
||||||
params[:search] = ActionController::Parameters.new
|
|
||||||
end
|
|
||||||
|
|
||||||
if params[:search].is_a?(ActionController::Parameters) && params[:search].values.any?(&:blank?)
|
deep_reject_blank = lambda do |hash|
|
||||||
params[:search].reject! {|k,v| v.blank?}
|
hash.reject { |k, v| v.blank? || (v.is_a?(Hash) && deep_reject_blank.call(v).blank?) }
|
||||||
redirect_to url_for(params: params.except(:controller, :action, :index).permit!)
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
get users_path, params: {:search => {:name_matches => @user.name}}
|
get users_path, params: {:search => {:name_matches => @user.name}}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "show action" do
|
context "show action" do
|
||||||
|
|||||||
Reference in New Issue
Block a user