FIX: links with query params to external sites fail to load if ga universal auto link domains is used

This commit is contained in:
Neil Lalonde 2017-12-13 13:58:36 -05:00
parent 8001f68c32
commit 3f1d6a302e
2 changed files with 32 additions and 0 deletions

View File

@ -34,6 +34,12 @@ class TopicLinkClick < ActiveRecord::Base
urls << url[0..query - 1] + url[endpos..-1]
end
# link can have query params, and analytics can add more to the end:
i = url.length
while i = url.rindex('&', i-1)
urls << url[0...i]
end
# add a cdn link
if uri
if Discourse.asset_host.present?

View File

@ -192,6 +192,32 @@ describe TopicLinkClick do
end
end
context 'with a query param and google analytics' do
before do
@topic = Fabricate(:topic)
@post = Fabricate(:post,
topic: @topic,
user: @topic.user,
raw: "Here's a link to twitter: http://twitter.com?ref=forum"
)
TopicLink.extract_from(@post)
@topic_link = @topic.topic_links.first
end
it 'creates a click' do
url = TopicLinkClick.create_from(
url: 'http://twitter.com?ref=forum&_ga=1.16846778.221554446.1071987018',
topic_id: @topic.id,
post_id: @post.id,
ip: '127.0.0.3'
)
click = TopicLinkClick.last
expect(click).to be_present
expect(click.topic_link).to eq(@topic_link)
expect(url).to eq('http://twitter.com?ref=forum&_ga=1.16846778.221554446.1071987018')
end
end
context 'with a google analytics tracking code and a hash' do
before do
@url = TopicLinkClick.create_from(url: 'http://discourse.org?_ga=1.16846778.221554446.1071987018#faq',