提交 98c7fe87 编写于 作者: A Aaron Patterson

unwrap the constraints object on initialization, eliminate loops

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.
上级 107c27bb
......@@ -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)
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册