diff --git a/app/models/person.rb b/app/models/person.rb index c44203e1e..8a9011fa4 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -27,21 +27,12 @@ class Person timestamps! - before_save :strip_and_downcase_diaspora_handle before_destroy :remove_all_traces before_validation :clean_url validates_presence_of :url, :profile, :serialized_public_key validates_format_of :url, :with => /^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix - - def strip_and_downcase_diaspora_handle - if self.diaspora_handle - self.diaspora_handle.strip! - self.diaspora_handle.downcase! - end - end - def self.search(query) return Person.all if query.to_s.empty? query_tokens = query.to_s.strip.split(" ") @@ -95,12 +86,14 @@ class Person def self.by_webfinger(identifier, opts = {}) #need to check if this is a valid email structure, maybe should do in JS - local_person = Person.first(:diaspora_handle => identifier.gsub('acct:', '').to_s) + query = /#{Regexp.escape(identifier.gsub('acct:', '').to_s)}/i + local_person = Person.first(:diaspora_handle => query) if local_person Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}") local_person elsif !identifier.include?("localhost") && !opts[:local] + #Get remote profile begin Rails.logger.info("Webfingering #{identifier}") f = Redfinger.finger(identifier) diff --git a/app/models/user.rb b/app/models/user.rb index 9351e34ef..1593ee29c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -388,7 +388,7 @@ class User end def diaspora_handle - "#{self.username}@#{APP_CONFIG[:terse_pod_url]}".downcase + "#{self.username}@#{APP_CONFIG[:terse_pod_url]}" end def as_json(opts={}) diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index a77aee76b..fd5ea0162 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -14,11 +14,6 @@ describe Person do end describe '#diaspora_handle' do - it 'should downcase and strip the handle before it saves' do - p = Factory.build(:person, :diaspora_handle => " FOOBaR@example.com ") - p.save - p.diaspora_handle.should == "foobar@example.com" - end context 'local people' do it 'uses the pod config url to set the diaspora_handle' do @user.person.diaspora_handle.should == @user.username + "@" + APP_CONFIG[:terse_pod_url] @@ -30,14 +25,20 @@ describe Person do @person.diaspora_handle.include?(APP_CONFIG[:terse_pod_url]).should be false end end + describe 'validation' do + it 'is unique' do + person_two = Factory.build(:person, :url => @person.diaspora_handle) + person_two.valid?.should be_false + end + + it 'is case insensitive' do + person_two = Factory.build(:person, :url => @person.diaspora_handle.upcase) + person_two.valid?.should be_false + end + end end - it 'should not allow two people with the same diaspora_handle' do - person_two = Factory.build(:person, :url => @person.diaspora_handle) - person_two.valid?.should == false - end - - describe 'xml' do + describe 'xml' do before do @xml = @person.to_xml.to_s end @@ -52,7 +53,7 @@ describe Person do end end - it 'should know when a post belongs to it' do + it '#owns? posts' do person_message = Factory.create(:status_message, :person => @person) person_two = Factory.create(:person) @@ -188,6 +189,12 @@ describe Person do person = Person.by_webfinger(user.person.diaspora_handle) person.should == user.person end + + it "is case insensitive" do + user = Factory(:user, :username => "SaMaNtHa") + person = Person.by_webfinger(user.person.diaspora_handle.upcase) + person.should == user.person + end end it 'creates a stub for a remote user' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d190fc27b..61e37b3aa 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -83,11 +83,6 @@ describe User do it 'uses the pod config url to set the diaspora_handle' do user.diaspora_handle.should == user.username + "@" + APP_CONFIG[:terse_pod_url] end - - it 'should be lowercase, even if username is uppercase' do - user.username = "fooBAR" - user.diaspora_handle.should == (user.username + "@" + APP_CONFIG[:terse_pod_url]).downcase - end end context 'profiles' do