FIX: Could not download exported data on some sites

This commit is contained in:
Robin Ward 2014-11-20 14:01:48 -05:00
parent b8d806ee07
commit dd1ebb535b
2 changed files with 27 additions and 0 deletions

View File

@ -31,6 +31,12 @@ class TopicLinkClick < ActiveRecord::Base
unless link.present?
return args[:url] if args[:url] =~ /^\//
begin
uri = URI.parse(args[:url])
return args[:url] if uri.host == URI.parse(Discourse.base_url).host
rescue
end
# If we have it somewhere else on the site, just allow the redirect. This is
# likely due to a onebox of another topic.
link = TopicLink.find_by(url: args[:url])

View File

@ -79,6 +79,27 @@ describe TopicLinkClick do
end
end
context "relative urls" do
let(:host) { URI.parse(Discourse.base_url).host }
it 'returns the url' do
url = TopicLinkClick.create_from(url: '/relative-url', post_id: @post.id, ip: '127.0.0.1')
url.should == "/relative-url"
end
it 'finds a protocol relative urls with a host' do
url = "//#{host}/relative-url"
redirect = TopicLinkClick.create_from(url: url)
redirect.should == url
end
it "returns the url if it's on our host" do
url = "http://#{host}/relative-url"
redirect = TopicLinkClick.create_from(url: url)
redirect.should == url
end
end
context 'with a HTTPS version of the same URL' do
before do
@url = TopicLinkClick.create_from(url: 'https://twitter.com', topic_id: @topic.id, ip: '127.0.0.3')