mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Could not download exported data on some sites
This commit is contained in:
@@ -31,6 +31,12 @@ class TopicLinkClick < ActiveRecord::Base
|
|||||||
unless link.present?
|
unless link.present?
|
||||||
return args[:url] if args[:url] =~ /^\//
|
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
|
# If we have it somewhere else on the site, just allow the redirect. This is
|
||||||
# likely due to a onebox of another topic.
|
# likely due to a onebox of another topic.
|
||||||
link = TopicLink.find_by(url: args[:url])
|
link = TopicLink.find_by(url: args[:url])
|
||||||
|
|||||||
@@ -79,6 +79,27 @@ describe TopicLinkClick do
|
|||||||
end
|
end
|
||||||
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
|
context 'with a HTTPS version of the same URL' do
|
||||||
before do
|
before do
|
||||||
@url = TopicLinkClick.create_from(url: 'https://twitter.com', topic_id: @topic.id, ip: '127.0.0.3')
|
@url = TopicLinkClick.create_from(url: 'https://twitter.com', topic_id: @topic.id, ip: '127.0.0.3')
|
||||||
|
|||||||
Reference in New Issue
Block a user