Skip to content
This repository
Browse code

Merge pull request #4916 from rmm5t/fix_force_ssl_redirect_with_params

Fixed force_ssl redirects to include original query params
  • Loading branch information...
commit f3595b5924c5d6245fb97c1ce13b3400ca11b1c8 2 parents 8c7378a + 0e482b3
José Valim josevalim authored
1  actionpack/lib/action_controller/metal/force_ssl.rb
@@ -29,6 +29,7 @@ def force_ssl(options = {})
29 29 if !request.ssl? && !Rails.env.development?
30 30 redirect_options = {:protocol => 'https://', :status => :moved_permanently}
31 31 redirect_options.merge!(:host => host) if host
  32 + redirect_options.merge!(:params => request.query_parameters)
32 33 redirect_to redirect_options
33 34 end
34 35 end
1  actionpack/lib/action_dispatch/routing/route_set.rb
@@ -575,6 +575,7 @@ def url_for(options)
575 575
576 576 path_addition, params = generate(path_options, path_segments || {})
577 577 path << path_addition
  578 + params.merge!(options[:params] || {})
578 579
579 580 ActionDispatch::Http::URL.url_for(options.merge!({
580 581 :path => path,
16 actionpack/test/controller/base_test.rb
@@ -257,6 +257,22 @@ def test_url_for_params_priority
257 257 assert_equal '/special', rs.url_for(url_params)
258 258 end
259 259
  260 + def test_url_for_query_params_included
  261 + rs = ActionDispatch::Routing::RouteSet.new
  262 + rs.draw do
  263 + match 'home' => 'pages#home'
  264 + end
  265 +
  266 + options = {
  267 + :action => "home",
  268 + :controller => "pages",
  269 + :only_path => true,
  270 + :params => { "token" => "secret" }
  271 + }
  272 +
  273 + assert_equal '/home?token=secret', rs.url_for(options)
  274 + end
  275 +
260 276 def test_url_options_override
261 277 with_routing do |set|
262 278 set.draw do
6 actionpack/test/controller/force_ssl_test.rb
@@ -35,6 +35,12 @@ def test_banana_redirects_to_https
35 35 assert_equal "https://test.host/force_ssl_controller_level/banana", redirect_to_url
36 36 end
37 37
  38 + def test_banana_redirects_to_https_with_extra_params
  39 + get :banana, :token => "secret"
  40 + assert_response 301
  41 + assert_equal "https://test.host/force_ssl_controller_level/banana?token=secret", redirect_to_url
  42 + end
  43 +
38 44 def test_cheeseburger_redirects_to_https
39 45 get :cheeseburger
40 46 assert_response 301

0 comments on commit f3595b5

Please sign in to comment.
Something went wrong with that request. Please try again.