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

Define word boundary for unanchored path regexp

This commit is contained in:
Petri Avikainen 2019-02-03 23:34:02 +02:00
parent 300c62f75c
commit c94754e2f0
No known key found for this signature in database
GPG key ID: D2315E803563CED4
3 changed files with 18 additions and 12 deletions

View file

@ -119,7 +119,7 @@ module ActionDispatch
class UnanchoredRegexp < AnchoredRegexp # :nodoc: class UnanchoredRegexp < AnchoredRegexp # :nodoc:
def accept(node) def accept(node)
%r{\A#{visit node}} %r{\A#{visit node}\b}
end end
end end

View file

@ -80,6 +80,12 @@ class TestRoutingMount < ActionDispatch::IntegrationTest
assert_equal "/shorthand -- /omg", response.body assert_equal "/shorthand -- /omg", response.body
end end
def test_mounting_does_not_match_similar_paths
get "/shorthandomg"
assert_not_equal "/shorthand -- /omg", response.body
assert_equal " -- /shorthandomg", response.body
end
def test_mounting_works_with_via def test_mounting_works_with_via
get "/getfake" get "/getfake"
assert_equal "OK", response.body assert_equal "OK", response.body

View file

@ -34,17 +34,17 @@ module ActionDispatch
end end
{ {
"/:controller(/:action)" => %r{\A/(#{x})(?:/([^/.?]+))?}, "/:controller(/:action)" => %r{\A/(#{x})(?:/([^/.?]+))?\b},
"/:controller/foo" => %r{\A/(#{x})/foo}, "/:controller/foo" => %r{\A/(#{x})/foo\b},
"/:controller/:action" => %r{\A/(#{x})/([^/.?]+)}, "/:controller/:action" => %r{\A/(#{x})/([^/.?]+)\b},
"/:controller" => %r{\A/(#{x})}, "/:controller" => %r{\A/(#{x})\b},
"/:controller(/:action(/:id))" => %r{\A/(#{x})(?:/([^/.?]+)(?:/([^/.?]+))?)?}, "/:controller(/:action(/:id))" => %r{\A/(#{x})(?:/([^/.?]+)(?:/([^/.?]+))?)?\b},
"/:controller/:action.xml" => %r{\A/(#{x})/([^/.?]+)\.xml}, "/:controller/:action.xml" => %r{\A/(#{x})/([^/.?]+)\.xml\b},
"/:controller.:format" => %r{\A/(#{x})\.([^/.?]+)}, "/:controller.:format" => %r{\A/(#{x})\.([^/.?]+)\b},
"/:controller(.:format)" => %r{\A/(#{x})(?:\.([^/.?]+))?}, "/:controller(.:format)" => %r{\A/(#{x})(?:\.([^/.?]+))?\b},
"/:controller/*foo" => %r{\A/(#{x})/(.+)}, "/:controller/*foo" => %r{\A/(#{x})/(.+)\b},
"/:controller/*foo/bar" => %r{\A/(#{x})/(.+)/bar}, "/:controller/*foo/bar" => %r{\A/(#{x})/(.+)/bar\b},
"/:foo|*bar" => %r{\A/(?:([^/.?]+)|(.+))}, "/:foo|*bar" => %r{\A/(?:([^/.?]+)|(.+))\b},
}.each do |path, expected| }.each do |path, expected|
define_method(:"test_to_non_anchored_regexp_#{Regexp.escape(path)}") do define_method(:"test_to_non_anchored_regexp_#{Regexp.escape(path)}") do
path = Pattern.build( path = Pattern.build(