mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Accept HTTPS or HTTP urls on redirect
This commit is contained in:
parent
8e5b736caa
commit
4f6283ba56
@ -11,8 +11,17 @@ class TopicLinkClick < ActiveRecord::Base
|
|||||||
# Create a click from a URL and post_id
|
# Create a click from a URL and post_id
|
||||||
def self.create_from(args={})
|
def self.create_from(args={})
|
||||||
|
|
||||||
|
# If the URL is absolute, allow HTTPS and HTTP versions of it
|
||||||
|
|
||||||
|
if args[:url] =~ /^http/
|
||||||
|
http_url = args[:url].sub(/^https/, 'http')
|
||||||
|
https_url = args[:url].sub(/^http[^s]/, 'https')
|
||||||
|
link = TopicLink.select([:id, :user_id]).where('url = ? OR url = ?', http_url, https_url)
|
||||||
|
else
|
||||||
|
link = TopicLink.select([:id, :user_id]).where(url: args[:url])
|
||||||
|
end
|
||||||
|
|
||||||
# Find the forum topic link
|
# Find the forum topic link
|
||||||
link = TopicLink.select([:id, :user_id]).where(url: args[:url])
|
|
||||||
link = link.where(post_id: args[:post_id]) if args[:post_id].present?
|
link = link.where(post_id: args[:post_id]) if args[:post_id].present?
|
||||||
|
|
||||||
# If we don't have a post, just find the first occurance of the link
|
# If we don't have a post, just find the first occurance of the link
|
||||||
|
@ -79,6 +79,19 @@ describe TopicLinkClick do
|
|||||||
end
|
end
|
||||||
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')
|
||||||
|
@click = TopicLinkClick.last
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a click' do
|
||||||
|
@click.should be_present
|
||||||
|
@click.topic_link.should == @topic_link
|
||||||
|
@url.should == 'https://twitter.com'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'with a valid url and topic_id' do
|
context 'with a valid url and topic_id' do
|
||||||
before do
|
before do
|
||||||
@url = TopicLinkClick.create_from(url: @topic_link.url, topic_id: @topic.id, ip: '127.0.0.3')
|
@url = TopicLinkClick.create_from(url: @topic_link.url, topic_id: @topic.id, ip: '127.0.0.3')
|
||||||
|
Loading…
Reference in New Issue
Block a user