mirror of
https://github.com/github/rails.git
synced 2026-01-10 07:07:54 -05:00
Merge pull request #4916 from rmm5t/fix_force_ssl_redirect_with_params
Fixed force_ssl redirects to include original query params
This commit is contained in:
@@ -29,6 +29,7 @@ module ActionController
|
||||
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)
|
||||
redirect_to redirect_options
|
||||
end
|
||||
end
|
||||
|
||||
@@ -575,6 +575,7 @@ module ActionDispatch
|
||||
|
||||
path_addition, params = generate(path_options, path_segments || {})
|
||||
path << path_addition
|
||||
params.merge!(options[:params] || {})
|
||||
|
||||
ActionDispatch::Http::URL.url_for(options.merge!({
|
||||
:path => path,
|
||||
|
||||
@@ -257,6 +257,22 @@ class UrlOptionsTest < ActionController::TestCase
|
||||
assert_equal '/special', rs.url_for(url_params)
|
||||
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
|
||||
|
||||
@@ -35,6 +35,12 @@ class ForceSSLControllerLevelTest < ActionController::TestCase
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user