diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb index cc3c7f20cbc4cf08b0fa18af033c8150a7b5a1bf..1ba91d548ecc592cb5216379049008602694b939 100644 --- a/actionpack/lib/action_dispatch/journey/route.rb +++ b/actionpack/lib/action_dispatch/journey/route.rb @@ -19,7 +19,7 @@ def initialize(name, app, path, constraints, defaults = {}) # Unwrap any constraints so we can see what's inside for route generation. # This allows the formatter to skip over any mounted applications or redirects # that shouldn't be matched when using a url_for without a route name. - while app.is_a?(Routing::Mapper::Constraints) do + if app.is_a?(Routing::Mapper::Constraints) app = app.app end @dispatcher = app.is_a?(Routing::RouteSet::Dispatcher) diff --git a/actionpack/lib/action_dispatch/routing/inspector.rb b/actionpack/lib/action_dispatch/routing/inspector.rb index 71a0c5e8268e38adbccbf4d19ddb1ee274a8f325..2135b280dae589f6317c6fae3683ac92bd872210 100644 --- a/actionpack/lib/action_dispatch/routing/inspector.rb +++ b/actionpack/lib/action_dispatch/routing/inspector.rb @@ -16,7 +16,7 @@ def rack_app(app = self.app) @rack_app ||= begin class_name = app.class.name.to_s if class_name == "ActionDispatch::Routing::Mapper::Constraints" - rack_app(app.app) + app.app elsif ActionDispatch::Routing::Redirect === app || class_name !~ /^ActionDispatch::Routing/ app end diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f39fd1ea35e5cca286f14f96c11869e0145d2171..b33c5e0dfd855a7784a0225435957022f941d597 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -19,6 +19,15 @@ class Constraints #:nodoc: attr_reader :app, :constraints def initialize(app, constraints, request) + # Unwrap Constraints objects. I don't actually think it's possible + # to pass a Constraints object to this constructor, but there were + # multiple places that kept testing children of this object. I + # *think* they were just being defensive, but I have no idea. + while app.is_a?(self.class) + constraints += app.constraints + app = app.app + end + @app, @constraints, @request = app, constraints, request end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 40c767e6852c1ab05cd97a8b1464106df5f4a839..924455bce22eeb2ed9c842b4bc9884dc4b0999f2 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -704,7 +704,7 @@ def recognize_path(path, environment = {}) old_params = req.path_parameters req.path_parameters = old_params.merge params dispatcher = route.app - while dispatcher.is_a?(Mapper::Constraints) && dispatcher.matches?(env) do + if dispatcher.is_a?(Mapper::Constraints) && dispatcher.matches?(env) dispatcher = dispatcher.app end