From da32661f10f0d14f392e987c50199c5ee71ed6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Apr 2010 14:04:46 +0200 Subject: Remove only formats in shortcuts and do it just once. --- actionpack/lib/action_dispatch/routing/mapper.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index ef2826a4e8..4b02c2deb3 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -64,10 +64,11 @@ module ActionDispatch end path = normalize_path(path) + path_without_format = path.sub(/\(\.:format\)$/, '') - if using_match_shorthand?(path, options) - options[:to] ||= path[1..-1].sub(%r{/([^/]*)$}, '#\1').sub(%r{\(.*\)}, '') - options[:as] ||= path[1..-1].gsub("/", "_").sub(%r{\(.*\)}, '') + if using_match_shorthand?(path_without_format, options) + options[:to] ||= path_without_format[1..-1].sub(%r{/([^/]*)$}, '#\1') + options[:as] ||= path_without_format[1..-1].gsub("/", "_") end [ path, options ] @@ -80,7 +81,7 @@ module ActionDispatch # match "account/overview" def using_match_shorthand?(path, options) - path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w+/?]+(\(.*\))*$} + path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w\/]+$} end def normalize_path(path) -- cgit v1.2.3