1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

use a parser to extract the group parts from the path

This commit is contained in:
Aaron Patterson 2014-05-29 14:57:48 -07:00
parent b5ea25bc44
commit 3a102a58f4
3 changed files with 9 additions and 5 deletions

View file

@ -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:

View file

@ -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)

View file

@ -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