Don't ignore constraints in redirect routes
402c2af550
introduced a regression that caused any constraints added to redirect routes
to be ignored.
Fixes #16605
This commit is contained in:
parent
53cc3ab46b
commit
d78f3f0ec3
@ -1,3 +1,10 @@
|
||||
* Fix bug where the router would ignore any constraints added to redirect
|
||||
routes.
|
||||
|
||||
Fixes #16605.
|
||||
|
||||
*Agis Anastasopoulos*
|
||||
|
||||
* Allow `config.action_dispatch.trusted_proxies` to accept an IPAddr object.
|
||||
|
||||
Example:
|
||||
|
@ -241,8 +241,6 @@ def add_request_method(via, conditions)
|
||||
end
|
||||
|
||||
def app(blocks)
|
||||
return to if Redirect === to
|
||||
|
||||
if to.respond_to?(:call)
|
||||
Constraints.new(to, blocks, false)
|
||||
else
|
||||
|
@ -14,6 +14,12 @@ def self.matches?(request)
|
||||
end
|
||||
end
|
||||
|
||||
class GrumpyRestrictor
|
||||
def self.matches?(request)
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
class YoutubeFavoritesRedirector
|
||||
def self.call(params, request)
|
||||
"http://www.youtube.com/watch?v=#{params[:youtube_id]}"
|
||||
@ -89,6 +95,24 @@ def test_namespace_redirect
|
||||
verify_redirect 'http://www.example.com/private/index'
|
||||
end
|
||||
|
||||
def test_redirect_with_failing_constraint
|
||||
draw do
|
||||
get 'hi', to: redirect("/foo"), constraints: ::TestRoutingMapper::GrumpyRestrictor
|
||||
end
|
||||
|
||||
get '/hi'
|
||||
assert_equal 404, status
|
||||
end
|
||||
|
||||
def test_redirect_with_passing_constraint
|
||||
draw do
|
||||
get 'hi', to: redirect("/foo"), constraints: ->(req) { true }
|
||||
end
|
||||
|
||||
get '/hi'
|
||||
assert_equal 301, status
|
||||
end
|
||||
|
||||
def test_namespace_with_controller_segment
|
||||
assert_raise(ArgumentError) do
|
||||
draw do
|
||||
|
Loading…
Reference in New Issue
Block a user