diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-12-01 07:55:29 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-12-01 07:55:29 -0800 |
commit | c9a5ed22d518a4c526457302f6a5e8abd152a57f (patch) | |
tree | 4e16ec09cea99e73dfffb57e4174bff64484f327 | |
parent | 07786c5e75a7b0afdf318063510af6b475e3e04c (diff) | |
parent | 0d690d75fbb088e967556ea186140ec96b320c42 (diff) | |
download | rails-c9a5ed22d518a4c526457302f6a5e8abd152a57f.tar.gz rails-c9a5ed22d518a4c526457302f6a5e8abd152a57f.tar.bz2 rails-c9a5ed22d518a4c526457302f6a5e8abd152a57f.zip |
Merge pull request #17827 from rkh/rkh-fix-or-pattern
Fix OR in Journey patterns
-rw-r--r-- | actionpack/lib/action_dispatch/journey/path/pattern.rb | 5 | ||||
-rw-r--r-- | actionpack/test/journey/path/pattern_test.rb | 2 |
2 files changed, 7 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/journey/path/pattern.rb b/actionpack/lib/action_dispatch/journey/path/pattern.rb index dca83e806c..64b48ca45f 100644 --- a/actionpack/lib/action_dispatch/journey/path/pattern.rb +++ b/actionpack/lib/action_dispatch/journey/path/pattern.rb @@ -122,6 +122,11 @@ module ActionDispatch re = @matchers[node.left.to_sym] || '.+' "(#{re})" end + + def visit_OR(node) + children = node.children.map { |n| visit n } + "(?:#{children.join(?|)})" + end end class UnanchoredRegexp < AnchoredRegexp # :nodoc: diff --git a/actionpack/test/journey/path/pattern_test.rb b/actionpack/test/journey/path/pattern_test.rb index 9dfdfc23ed..6939b426f6 100644 --- a/actionpack/test/journey/path/pattern_test.rb +++ b/actionpack/test/journey/path/pattern_test.rb @@ -16,6 +16,7 @@ module ActionDispatch '/:controller(.:format)' => %r{\A/(#{x})(?:\.([^/.?]+))?\Z}, '/:controller/*foo' => %r{\A/(#{x})/(.+)\Z}, '/:controller/*foo/bar' => %r{\A/(#{x})/(.+)/bar\Z}, + '/:foo|*bar' => %r{\A/(?:([^/.?]+)|(.+))\Z}, }.each do |path, expected| define_method(:"test_to_regexp_#{path}") do strexp = Router::Strexp.build( @@ -39,6 +40,7 @@ module ActionDispatch '/:controller(.:format)' => %r{\A/(#{x})(?:\.([^/.?]+))?}, '/:controller/*foo' => %r{\A/(#{x})/(.+)}, '/:controller/*foo/bar' => %r{\A/(#{x})/(.+)/bar}, + '/:foo|*bar' => %r{\A/(?:([^/.?]+)|(.+))}, }.each do |path, expected| define_method(:"test_to_non_anchored_regexp_#{path}") do strexp = Router::Strexp.build( |