提交 0d690d75 编写于 作者: K Konstantin Haase

make OR in journey patterns compile to a valid regular expression

上级 b599f992
......@@ -122,6 +122,11 @@ def visit_STAR(node)
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:
......
......@@ -16,6 +16,7 @@ class TestPattern < ActiveSupport::TestCase
'/: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 @@ class TestPattern < ActiveSupport::TestCase
'/: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(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册