diff options
author | Prem Sichanugrist <s@sikachu.com> | 2011-03-29 02:59:24 +0700 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2011-03-29 10:12:17 +0100 |
commit | 51551a0a5bd6f7e4116bc3759a4d7c15634643dc (patch) | |
tree | c5502f9dc06798f1e1321b69119c2b24b69c1095 /actionpack/lib/action_dispatch/routing | |
parent | 3d1e7c2645af6c187d5ab6d2a02bd1e7b9ad7af3 (diff) | |
download | rails-51551a0a5bd6f7e4116bc3759a4d7c15634643dc.tar.gz rails-51551a0a5bd6f7e4116bc3759a4d7c15634643dc.tar.bz2 rails-51551a0a5bd6f7e4116bc3759a4d7c15634643dc.zip |
Update the wildcard route to be non-greedy by default, therefore be able to match the (.:format) segment [#6605 state:resolved]
After some discussion with Andrew White, it seems like this is a better approach for handling a wildcard route. However, user can still bring back the old behavior by supplying `:format => false` to the route.
Signed-off-by: Andrew White <andyw@pixeltrix.co.uk>
Diffstat (limited to 'actionpack/lib/action_dispatch/routing')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 14c424f24b..35be0b3a27 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -104,10 +104,16 @@ module ActionDispatch @options.reverse_merge!(:controller => /.+?/) end + # Add a constraint for wildcard route to make it non-greedy and match the + # optional format part of the route by default + if path.match(/\*([^\/]+)$/) && @options[:format] != false + @options.reverse_merge!(:"#{$1}" => /.+?/) + end + if @options[:format] == false @options.delete(:format) path - elsif path.include?(":format") || path.end_with?('/') || path.match(/^\/?\*/) + elsif path.include?(":format") || path.end_with?('/') path else "#{path}(.:format)" |