diff --git a/lib/admin_user_index_query.rb b/lib/admin_user_index_query.rb index 0cf304d422f..3c2eeec9d31 100644 --- a/lib/admin_user_index_query.rb +++ b/lib/admin_user_index_query.rb @@ -79,6 +79,7 @@ class AdminUserIndexQuery def filter_by_search if params[:filter].present? + params[:filter].strip! if ip = IPAddr.new(params[:filter]) rescue nil @query.where('ip_address <<= :ip OR registration_ip_address <<= :ip', ip: ip.to_cidr_s) else @@ -89,7 +90,7 @@ class AdminUserIndexQuery def filter_by_ip if params[:ip].present? - @query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:ip]) + @query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:ip].strip) end end diff --git a/spec/components/admin_user_index_query_spec.rb b/spec/components/admin_user_index_query_spec.rb index 7d03cf1e311..a4a7e48abf2 100644 --- a/spec/components/admin_user_index_query_spec.rb +++ b/spec/components/admin_user_index_query_spec.rb @@ -110,12 +110,12 @@ describe AdminUserIndexQuery do before(:each) { Fabricate(:user, email: "test1@example.com") } it "matches the email" do - query = ::AdminUserIndexQuery.new({ filter: "est1" }) + query = ::AdminUserIndexQuery.new({ filter: " est1" }) expect(query.find_users.count()).to eq(1) end it "matches the email using any case" do - query = ::AdminUserIndexQuery.new({ filter: "Test1" }) + query = ::AdminUserIndexQuery.new({ filter: "Test1\t" }) expect(query.find_users.count()).to eq(1) end @@ -126,12 +126,12 @@ describe AdminUserIndexQuery do before(:each) { Fabricate(:user, username: "test_user_1") } it "matches the username" do - query = ::AdminUserIndexQuery.new({ filter: "user" }) + query = ::AdminUserIndexQuery.new({ filter: "user\n" }) expect(query.find_users.count).to eq(1) end it "matches the username using any case" do - query = ::AdminUserIndexQuery.new({ filter: "User" }) + query = ::AdminUserIndexQuery.new({ filter: "\r\nUser" }) expect(query.find_users.count).to eq(1) end end @@ -141,7 +141,7 @@ describe AdminUserIndexQuery do let!(:user) { Fabricate(:user, ip_address: "117.207.94.9") } it "matches the ip address" do - query = ::AdminUserIndexQuery.new({ filter: "117.207.94.9" }) + query = ::AdminUserIndexQuery.new({ filter: " 117.207.94.9 " }) expect(query.find_users.count()).to eq(1) end