aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-04-20 14:04:46 +0200
committerJosé Valim <jose.valim@gmail.com>2010-04-20 21:19:48 +0200
commitda32661f10f0d14f392e987c50199c5ee71ed6e8 (patch)
tree25fa24bcca0cec431e6e47982e1e4dddc3acf396 /actionpack/lib
parent2e3d903e1b54c1a37f29ed5168ee969d1ad9b55b (diff)
downloadrails-da32661f10f0d14f392e987c50199c5ee71ed6e8.tar.gz
rails-da32661f10f0d14f392e987c50199c5ee71ed6e8.tar.bz2
rails-da32661f10f0d14f392e987c50199c5ee71ed6e8.zip
Remove only formats in shortcuts and do it just once.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb9
1 files 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)