mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #35162 from silppuri/fix-incorrectly-matching-unachored-paths
Fix incorrectly matching unanchored paths
This commit is contained in:
commit
3127f5783e
3 changed files with 18 additions and 12 deletions
|
@ -119,7 +119,7 @@ module ActionDispatch
|
|||
|
||||
class UnanchoredRegexp < AnchoredRegexp # :nodoc:
|
||||
def accept(node)
|
||||
%r{\A#{visit node}}
|
||||
%r{\A#{visit node}(?:\b|\Z)}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -80,6 +80,12 @@ class TestRoutingMount < ActionDispatch::IntegrationTest
|
|||
assert_equal "/shorthand -- /omg", response.body
|
||||
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
|
||||
get "/getfake"
|
||||
assert_equal "OK", response.body
|
||||
|
|
|
@ -34,17 +34,17 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
{
|
||||
"/:controller(/:action)" => %r{\A/(#{x})(?:/([^/.?]+))?},
|
||||
"/:controller/foo" => %r{\A/(#{x})/foo},
|
||||
"/:controller/:action" => %r{\A/(#{x})/([^/.?]+)},
|
||||
"/:controller" => %r{\A/(#{x})},
|
||||
"/:controller(/:action(/:id))" => %r{\A/(#{x})(?:/([^/.?]+)(?:/([^/.?]+))?)?},
|
||||
"/:controller/:action.xml" => %r{\A/(#{x})/([^/.?]+)\.xml},
|
||||
"/:controller.:format" => %r{\A/(#{x})\.([^/.?]+)},
|
||||
"/:controller(.:format)" => %r{\A/(#{x})(?:\.([^/.?]+))?},
|
||||
"/:controller/*foo" => %r{\A/(#{x})/(.+)},
|
||||
"/:controller/*foo/bar" => %r{\A/(#{x})/(.+)/bar},
|
||||
"/:foo|*bar" => %r{\A/(?:([^/.?]+)|(.+))},
|
||||
"/:controller(/:action)" => %r{\A/(#{x})(?:/([^/.?]+))?(?:\b|\Z)},
|
||||
"/:controller/foo" => %r{\A/(#{x})/foo(?:\b|\Z)},
|
||||
"/:controller/:action" => %r{\A/(#{x})/([^/.?]+)(?:\b|\Z)},
|
||||
"/:controller" => %r{\A/(#{x})(?:\b|\Z)},
|
||||
"/:controller(/:action(/:id))" => %r{\A/(#{x})(?:/([^/.?]+)(?:/([^/.?]+))?)?(?:\b|\Z)},
|
||||
"/:controller/:action.xml" => %r{\A/(#{x})/([^/.?]+)\.xml(?:\b|\Z)},
|
||||
"/:controller.:format" => %r{\A/(#{x})\.([^/.?]+)(?:\b|\Z)},
|
||||
"/:controller(.:format)" => %r{\A/(#{x})(?:\.([^/.?]+))?(?:\b|\Z)},
|
||||
"/:controller/*foo" => %r{\A/(#{x})/(.+)(?:\b|\Z)},
|
||||
"/:controller/*foo/bar" => %r{\A/(#{x})/(.+)/bar(?:\b|\Z)},
|
||||
"/:foo|*bar" => %r{\A/(?:([^/.?]+)|(.+))(?:\b|\Z)},
|
||||
}.each do |path, expected|
|
||||
define_method(:"test_to_non_anchored_regexp_#{Regexp.escape(path)}") do
|
||||
path = Pattern.build(
|
||||
|
|
Loading…
Reference in a new issue