diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-29 14:57:48 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-29 14:57:48 -0700 |
commit | 3a102a58f4d33f9a8c660f617fe1242d7baa9f90 (patch) | |
tree | 882f50430559409b8eaa47ff06d040081cc7be6e /actionpack | |
parent | b5ea25bc44ceb07f1828b7b7f67bec700d96e216 (diff) | |
download | rails-3a102a58f4d33f9a8c660f617fe1242d7baa9f90.tar.gz rails-3a102a58f4d33f9a8c660f617fe1242d7baa9f90.tar.bz2 rails-3a102a58f4d33f9a8c660f617fe1242d7baa9f90.zip |
use a parser to extract the group parts from the path
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/journey/nodes/node.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 6 | ||||
-rw-r--r-- | actionpack/test/dispatch/mapper_test.rb | 4 |
3 files changed, 9 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/journey/nodes/node.rb b/actionpack/lib/action_dispatch/journey/nodes/node.rb index 935442ef66..bb01c087bc 100644 --- a/actionpack/lib/action_dispatch/journey/nodes/node.rb +++ b/actionpack/lib/action_dispatch/journey/nodes/node.rb @@ -93,6 +93,10 @@ module ActionDispatch class Star < Unary # :nodoc: def type; :STAR; end + + def name + left.name.tr '*:', '' + end end class Binary < Node # :nodoc: diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 503f70bd5f..ca9f00c92e 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -108,12 +108,12 @@ module ActionDispatch end def normalize_options!(options, path_params) - path_without_format = path.sub(/\(\.:format\)$/, '') + wildcards = path_ast(path).grep(Journey::Nodes::Star).map(&:name) # Add a constraint for wildcard route to make it non-greedy and match the # optional format part of the route by default - if path_without_format.match(WILDCARD_PATH) && options[:format] != false - options[$1.to_sym] ||= /.+?/ + if wildcards.any? && options[:format] != false + wildcards.each { |wc| options[wc.to_sym] ||= /.+?/ } end if path_params.include?(:controller) diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 58457b0c28..e3dcf9b88a 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -72,7 +72,7 @@ module ActionDispatch mapper = Mapper.new fakeset mapper.get '/*path/foo/:bar', :to => 'pages#show' assert_equal '/*path/foo/:bar(.:format)', fakeset.conditions.first[:path_info] - assert_nil fakeset.requirements.first[:path] + assert_equal(/.+?/, fakeset.requirements.first[:path]) end def test_map_wildcard_with_multiple_wildcard @@ -80,7 +80,7 @@ module ActionDispatch mapper = Mapper.new fakeset mapper.get '/*foo/*bar', :to => 'pages#show' assert_equal '/*foo/*bar(.:format)', fakeset.conditions.first[:path_info] - assert_nil fakeset.requirements.first[:foo] + assert_equal(/.+?/, fakeset.requirements.first[:foo]) assert_equal(/.+?/, fakeset.requirements.first[:bar]) end |