diff --git a/app/models/jobs/http_multi.rb b/app/models/jobs/http_multi.rb index 26359d70e..814645c1e 100644 --- a/app/models/jobs/http_multi.rb +++ b/app/models/jobs/http_multi.rb @@ -1,3 +1,9 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'uri' + module Job class HttpMulti < Base @queue = :http @@ -24,7 +30,11 @@ module Job request.on_complete do |response| if response.code >= 300 && response.code < 400 if response.headers_hash['Location'] == response.request.url.sub('http://', 'https://') - person.url = response.headers_hash['Location'] + location = URI.parse(response.headers_hash['Location']) + newuri = "#{location.scheme}://#{location.host}" + newuri += ":#{location.port}" unless ["80", "443"].include?(location.port.to_s) + newuri += "/" + person.url = newuri person.save end end diff --git a/app/models/person.rb b/app/models/person.rb index 510361a59..3be94302a 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -2,6 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. +require 'uri' require File.join(Rails.root, 'lib/hcard') class Person < ActiveRecord::Base @@ -93,13 +94,25 @@ class Person < ActiveRecord::Base def owns?(post) self == post.person end + + def url + begin + uri = URI.parse(@attributes['url']) + url = "#{uri.scheme}://#{uri.host}" + url += ":#{uri.port}" unless ["80", "443"].include?(uri.port.to_s) + url += "/" + rescue Exception => e + url = @attributes['url'] + end + url + end def receive_url - "#{self.url}receive/users/#{self.guid}/" + "#{url}receive/users/#{self.guid}/" end def public_url - "#{self.url}public/#{self.owner.username}" + "#{url}public/#{self.owner.username}" end def public_key_hash diff --git a/config/locale_settings.yml b/config/locale_settings.yml index 63af26001..2bc3842c3 100644 --- a/config/locale_settings.yml +++ b/config/locale_settings.yml @@ -34,22 +34,11 @@ available: tr: 'Türk' zh: '中文' fallbacks: - en-GB: - - :en - en-US: - - :en - en_shaw: - - :en - - :en-GB - - :en-US - sv: - - :sv-SE - he: - - :he-IL - es-CL: - - :es - gl: - - :gl-ES - zh: - - :zh-CN - - :zh-TW + en-GB: [:en] + en-US: [:en] + en_shaw: [:en, :en-GB, :en-US] + sv: [:sv-SE] + he: [:he-IL] + es-CL: [:es] + gl: [:gl-ES] + zh: [:zh-CN, :zh-TW] diff --git a/spec/models/jobs/http_multi_spec.rb b/spec/models/jobs/http_multi_spec.rb index 509c9a800..be04806be 100644 --- a/spec/models/jobs/http_multi_spec.rb +++ b/spec/models/jobs/http_multi_spec.rb @@ -72,6 +72,6 @@ describe Job::HttpMulti do Job::HttpMulti.perform(bob.id, @post_xml, [person.id]) person.reload - person.url.should =~ /https:\/\/remote.net\// + person.url.should == "https://remote.net/" end end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 319c5eb72..67c53dc35 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -20,11 +20,21 @@ describe Person do end describe "vaild url" do - it 'should allow for https urls' do + it 'should allow for https urls' do person = Factory.create(:person, :url => "https://example.com") person.should be_valid - end end + + it 'should always return the correct receive url' do + person = Factory.create(:person, :url => "https://example.com/a/bit/messed/up") + person.receive_url.should == "https://example.com/receive/users/#{person.guid}/" + end + + it 'should allow ports in the url' do + person = Factory.create(:person, :url => "https://example.com:3000/") + person.url.should == "https://example.com:3000/" + end + end describe '#diaspora_handle' do