mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #41390 from ojab/allow_uri_in_redirect
Allow passing anything with `#to_str` into `redirect_to`
This commit is contained in:
commit
a95e5a9c55
3 changed files with 21 additions and 1 deletions
|
@ -48,6 +48,10 @@
|
|||
|
||||
*Janko Marohnić*
|
||||
|
||||
* Allow anything with `#to_str` (like `Addressable::URI`) as a `redirect_to` location
|
||||
|
||||
*ojab*
|
||||
|
||||
* Change the request method to a `GET` when passing failed requests down to `config.exceptions_app`.
|
||||
|
||||
*Alex Robbin*
|
||||
|
|
|
@ -106,7 +106,7 @@ module ActionController
|
|||
# See https://tools.ietf.org/html/rfc3986#section-3.1
|
||||
# The protocol relative scheme starts with a double slash "//".
|
||||
when /\A([a-z][a-z\d\-+.]*:|\/\/).*/i
|
||||
options
|
||||
options.to_str
|
||||
when String
|
||||
request.protocol + request.host_with_port + options
|
||||
when Proc
|
||||
|
|
|
@ -96,6 +96,16 @@ class RedirectController < ActionController::Base
|
|||
redirect_to "http://www.rubyonrails.org/"
|
||||
end
|
||||
|
||||
def redirect_to_url_with_stringlike
|
||||
stringlike = Object.new
|
||||
|
||||
def stringlike.to_str
|
||||
"http://www.rubyonrails.org/"
|
||||
end
|
||||
|
||||
redirect_to stringlike
|
||||
end
|
||||
|
||||
def redirect_to_url_with_unescaped_query_string
|
||||
redirect_to "http://example.com/query?status=new"
|
||||
end
|
||||
|
@ -257,6 +267,12 @@ class RedirectTest < ActionController::TestCase
|
|||
assert_redirected_to "http://www.rubyonrails.org/"
|
||||
end
|
||||
|
||||
def test_redirect_to_url_with_stringlike
|
||||
get :redirect_to_url_with_stringlike
|
||||
assert_response :redirect
|
||||
assert_redirected_to "http://www.rubyonrails.org/"
|
||||
end
|
||||
|
||||
def test_redirect_to_url_with_unescaped_query_string
|
||||
get :redirect_to_url_with_unescaped_query_string
|
||||
assert_response :redirect
|
||||
|
|
Loading…
Reference in a new issue