Permalink
Browse files

use a parser to extract the group parts from the path

  • Loading branch information...
1 parent b5ea25b commit 3a102a58f4d33f9a8c660f617fe1242d7baa9f90 @tenderlove tenderlove committed May 29, 2014
@@ -93,6 +93,10 @@ def type; :GROUP; end
class Star < Unary # :nodoc:
def type; :STAR; end
+
+ def name
+ left.name.tr '*:', ''
+ end
end
class Binary < Node # :nodoc:
@@ -108,12 +108,12 @@ def optional_format?(path, format)
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)
@@ -72,15 +72,15 @@ def test_map_wildcard_with_other_element
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
fakeset = FakeSet.new
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

0 comments on commit 3a102a5

Please sign in to comment.