Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix force_ssl redirect with params #4928

Merged
merged 2 commits into from

2 participants

Ryan McGeary José Valim
Ryan McGeary

This is a cherry-pick from 3-2-stable. For more info, see #4916


ActionController.force_ssl redirects http URLs to their https equivalent; however, when a URL contains a query string, the resulting redirect lacked the original query string.

For example, this URL (with force_ssl):

http://example.com/widgets/new?name=foo

Only redirects to:

https://example.com/widgets/new
rmm5t added some commits
Ryan McGeary rmm5t Fixed force_ssl redirects to include original query params
`ActionController.force_ssl` redirects http URLs to their https equivalent;
however, when a URL contains a query string, the resulting redirect lacked the
original query string.

Conflicts:

	actionpack/lib/action_controller/metal/force_ssl.rb
6efb849
Ryan McGeary rmm5t Added unit test to cover changes to RouteSet.url_for
ActionDispatch::Routing::RouteSet.url_for now handles passing params through to
ActionDispatch::Http::Url.url_for

Conflicts:

	actionpack/test/controller/base_test.rb
30e5503
José Valim josevalim merged commit 12c3b3d into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 7, 2012
  1. Ryan McGeary

    Fixed force_ssl redirects to include original query params

    rmm5t authored
    `ActionController.force_ssl` redirects http URLs to their https equivalent;
    however, when a URL contains a query string, the resulting redirect lacked the
    original query string.
    
    Conflicts:
    
    	actionpack/lib/action_controller/metal/force_ssl.rb
  2. Ryan McGeary

    Added unit test to cover changes to RouteSet.url_for

    rmm5t authored
    ActionDispatch::Routing::RouteSet.url_for now handles passing params through to
    ActionDispatch::Http::Url.url_for
    
    Conflicts:
    
    	actionpack/test/controller/base_test.rb
This page is out of date. Refresh to see the latest.
1  actionpack/lib/action_controller/metal/force_ssl.rb
View
@@ -29,6 +29,7 @@ def force_ssl(options = {})
if !request.ssl? && !Rails.env.development?
redirect_options = {:protocol => 'https://', :status => :moved_permanently}
redirect_options.merge!(:host => host) if host
+ redirect_options.merge!(:params => request.query_parameters)
flash.keep
redirect_to redirect_options
end
1  actionpack/lib/action_dispatch/routing/route_set.rb
View
@@ -567,6 +567,7 @@ def url_for(options)
path_addition, params = generate(path_options, path_segments || {})
path << path_addition
+ params.merge!(options[:params] || {})
ActionDispatch::Http::URL.url_for(options.merge!({
:path => path,
16 actionpack/test/controller/base_test.rb
View
@@ -158,6 +158,22 @@ def setup
rescue_action_in_public!
end
+ def test_url_for_query_params_included
+ rs = ActionDispatch::Routing::RouteSet.new
+ rs.draw do
+ match 'home' => 'pages#home'
+ end
+
+ options = {
+ :action => "home",
+ :controller => "pages",
+ :only_path => true,
+ :params => { "token" => "secret" }
+ }
+
+ assert_equal '/home?token=secret', rs.url_for(options)
+ end
+
def test_url_options_override
with_routing do |set|
set.draw do
6 actionpack/test/controller/force_ssl_test.rb
View
@@ -50,6 +50,12 @@ def test_banana_redirects_to_https
assert_equal "https://test.host/force_ssl_controller_level/banana", redirect_to_url
end
+ def test_banana_redirects_to_https_with_extra_params
+ get :banana, :token => "secret"
+ assert_response 301
+ assert_equal "https://test.host/force_ssl_controller_level/banana?token=secret", redirect_to_url
+ end
+
def test_cheeseburger_redirects_to_https
get :cheeseburger
assert_response 301
Something went wrong with that request. Please try again.