From bc4872d3a54844482623f58a941473bf06fdd059 Mon Sep 17 00:00:00 2001 From: Jonne Hass <mrzyx@mrzyx.de> Date: Wed, 7 Sep 2011 15:17:31 +0200 Subject: [PATCH] ensure handle is downcased on search, fix #1912 --- app/controllers/people_controller.rb | 2 +- lib/webfinger.rb | 2 +- spec/controllers/people_controller_spec.rb | 8 ++++++++ spec/lib/webfinger_spec.rb | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index e89ecb3876..fbd8be043a 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -33,7 +33,7 @@ class PeopleController < ApplicationController format.html do #only do it if it is an email address if params[:q].try(:match, Devise.email_regexp) - people = Person.where(:diaspora_handle => params[:q]) + people = Person.where(:diaspora_handle => params[:q].downcase) webfinger(params[:q]) if people.empty? else people = Person.search(params[:q], current_user) diff --git a/lib/webfinger.rb b/lib/webfinger.rb index 2b742afa46..d22f7aba05 100644 --- a/lib/webfinger.rb +++ b/lib/webfinger.rb @@ -4,7 +4,7 @@ require File.join(Rails.root, 'lib/webfinger_profile') class Webfinger class WebfingerFailedError < RuntimeError; end def initialize(account) - @account = account.strip.gsub('acct:','').to_s + @account = account.strip.gsub('acct:','').to_s.downcase @ssl = true Rails.logger.info("event=webfinger status=initialized target=#{account}") end diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 598b0e63d8..c0525b2e82 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -57,6 +57,14 @@ describe PeopleController do get :index, :q => "eugene@example.org" assigns[:people][0].id.should == eugene2.id end + + it "downcases the handle before trying to find someone by it" do + eugene2 = Factory.create(:person, :diaspora_handle => "eugene@example.org", + :profile => Factory.build(:profile, :first_name => "Eugene", + :last_name => "w", :searchable => false)) + get :index, :q => "Eugene@Example.ORG" + assigns[:people][0].id.should == eugene2.id + end it "does not redirect to person page if there is exactly one match" do get :index, :q => "Korth" diff --git a/spec/lib/webfinger_spec.rb b/spec/lib/webfinger_spec.rb index 25002e5c80..305ab36146 100644 --- a/spec/lib/webfinger_spec.rb +++ b/spec/lib/webfinger_spec.rb @@ -32,6 +32,12 @@ describe Webfinger do n = Webfinger.new("mbs348@gmail.com") n.instance_variable_get(:@account).should_not be nil end + + it 'downcases account' do + account = "BIGBOY@Example.Org" + n = Webfinger.new(account) + n.instance_variable_get(:@account).should == account.downcase + end it 'should set ssl as the default' do foo = Webfinger.new(account) -- GitLab