From 35933822dec7be3f895c7a3f1440d72c982aebdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 14 Jan 2010 01:31:17 +0100 Subject: Ensure optional path scopes are properly handled. --- actionpack/lib/action_dispatch/routing/mapper.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 5009ed001c..bad90df2e3 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -68,13 +68,9 @@ module ActionDispatch end def normalize_path(path) - path = nil if path == "" - path = "#{@scope[:path]}#{path}" if @scope[:path] - path = Rack::Mount::Utils.normalize_path(path) if path - - raise ArgumentError, "path is required" unless path - - path + path = "#{@scope[:path]}#{path}" + raise ArgumentError, "path is required" if path.empty? + Mapper.normalize_path(path) end def app @@ -160,6 +156,14 @@ module ActionDispatch end end + # Invokes Rack::Mount::Utils.normalize path and ensure that + # (:locale) becomes (/:locale) instead of /(:locale). + def self.normalize_path(path) + path = Rack::Mount::Utils.normalize_path(path) + path.sub!(/^\/\(+\/?:/, '(/:') + path + end + module Base def initialize(set) @set = set @@ -245,7 +249,7 @@ module ActionDispatch if path = options.delete(:path) path_set = true - path, @scope[:path] = @scope[:path], Rack::Mount::Utils.normalize_path(@scope[:path].to_s + path.to_s) + path, @scope[:path] = @scope[:path], Mapper.normalize_path(@scope[:path].to_s + path.to_s) else path_set = false end -- cgit v1.2.3