aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb5
-rw-r--r--actionpack/test/dispatch/routing_test.rb21
2 files changed, 17 insertions, 9 deletions
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
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 6dccabdb3f..dfe824fd70 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -141,19 +141,18 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
resources :rooms
end
- scope '(:locale)', :locale => /en|pl/ do
- resources :descriptions
- end
+ match '/info' => 'projects#info', :as => 'info'
namespace :admin do
- scope '(/:locale)', :locale => /en|pl/ do
+ scope '(:locale)', :locale => /en|pl/ do
resources :descriptions
end
end
- match '/info' => 'projects#info', :as => 'info'
-
- root :to => 'projects#index'
+ scope '(:locale)', :locale => /en|pl/ do
+ resources :descriptions
+ root :to => 'projects#index'
+ end
end
end
@@ -660,6 +659,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_optional_scoped_root
+ with_test_routes do
+ assert_equal '/en', root_path("en")
+ get '/en'
+ assert_equal 'projects#index', @response.body
+ end
+ end
+
def test_optional_scoped_path
with_test_routes do
assert_equal '/en/descriptions', descriptions_path("en")