From 06e9cbc6cb26625d30c88d4d5acd6ada6404ef7f Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 13 Dec 2013 12:56:20 -0500 Subject: [PATCH] FIX: Look up a url without the query string if it couldn't be found with it. --- app/controllers/clicks_controller.rb | 6 ++++++ spec/controllers/clicks_controller_spec.rb | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/app/controllers/clicks_controller.rb b/app/controllers/clicks_controller.rb index 8472c9e7ff2..056a8e84d70 100644 --- a/app/controllers/clicks_controller.rb +++ b/app/controllers/clicks_controller.rb @@ -8,6 +8,12 @@ class ClicksController < ApplicationController if params[:topic_id].present? || params[:post_id].present? params.merge!({ user_id: current_user.id }) if current_user.present? @redirect_url = TopicLinkClick.create_from(params) + + if @redirect_url.blank? && params[:url].index('?') + # Check the url without query parameters + params[:url].sub!(/\?.*$/, '') + @redirect_url = TopicLinkClick.create_from(params) + end end # Sometimes we want to record a link without a 302. Since XHR has to load the redirected diff --git a/spec/controllers/clicks_controller_spec.rb b/spec/controllers/clicks_controller_spec.rb index a28d575c30d..6d88633d74f 100644 --- a/spec/controllers/clicks_controller_spec.rb +++ b/spec/controllers/clicks_controller_spec.rb @@ -28,7 +28,14 @@ describe ClicksController do xhr :get, :track, url: 'http://discourse.org', post_id: 123 response.should_not be_redirect end + end + context "with a query string" do + it "tries again without the query if it fails" do + TopicLinkClick.expects(:create_from).with(has_entries('url' => 'http://discourse.org/?hello=123')).returns(nil) + TopicLinkClick.expects(:create_from).with(has_entries('url' => 'http://discourse.org/')).returns(nil) + xhr :get, :track, url: 'http://discourse.org/?hello=123', post_id: 123 + end end context 'with a post_id' do