From 3a102a58f4d33f9a8c660f617fe1242d7baa9f90 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 29 May 2014 14:57:48 -0700 Subject: use a parser to extract the group parts from the path --- actionpack/lib/action_dispatch/journey/nodes/node.rb | 4 ++++ actionpack/lib/action_dispatch/routing/mapper.rb | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_dispatch') 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) -- cgit v1.2.3