aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/middleware/stack.rb14
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb5
2 files changed, 16 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb
index 0dc1d70e37..18a2922fa7 100644
--- a/actionpack/lib/action_dispatch/middleware/stack.rb
+++ b/actionpack/lib/action_dispatch/middleware/stack.rb
@@ -55,7 +55,11 @@ module ActionDispatch
when Class
klass == middleware
else
- klass == ActiveSupport::Inflector.constantize(middleware.to_s)
+ if lazy_compare?(@klass) && lazy_compare?(middleware)
+ normalize(@klass) == normalize(middleware)
+ else
+ klass == ActiveSupport::Inflector.constantize(middleware.to_s)
+ end
end
end
@@ -72,6 +76,14 @@ module ActionDispatch
end
private
+ def lazy_compare?(object)
+ object.is_a?(String) || object.is_a?(Symbol)
+ end
+
+ def normalize(object)
+ object.to_s.strip.sub(/^::/, '')
+ end
+
def build_args
Array(args).map { |arg| arg.respond_to?(:call) ? arg.call : arg }
end
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index fcbb70749f..5199984814 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -157,10 +157,11 @@ module ActionDispatch
end
# Invokes Rack::Mount::Utils.normalize path and ensure that
- # (:locale) becomes (/:locale) instead of /(:locale).
+ # (:locale) becomes (/:locale) instead of /(:locale). Except
+ # for root cases, where the latter is the correct one.
def self.normalize_path(path)
path = Rack::Mount::Utils.normalize_path(path)
- path.sub!(%r{/\(+/?:}, '(/:')
+ path.sub!(%r{/(\(+)/?:}, '\1/:') unless path =~ %r{^/\(+:.*\)$}
path
end