mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #35975 from xithan/master
mounted routes with non-word characters
This commit is contained in:
commit
60afbfffdc
3 changed files with 22 additions and 12 deletions
|
@ -119,7 +119,8 @@ module ActionDispatch
|
|||
|
||||
class UnanchoredRegexp < AnchoredRegexp # :nodoc:
|
||||
def accept(node)
|
||||
%r{\A#{visit node}(?:\b|\Z)}
|
||||
path = visit node
|
||||
path == "/" ? %r{\A/} : %r{\A#{path}(?:\b|\Z|/)}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class TestRoutingMount < ActionDispatch::IntegrationTest
|
|||
}
|
||||
|
||||
mount SprocketsApp, at: "/sprockets"
|
||||
mount SprocketsApp, at: "/star*"
|
||||
mount SprocketsApp => "/shorthand"
|
||||
|
||||
mount SinatraLikeApp, at: "/fakeengine", as: :fake
|
||||
|
@ -58,6 +59,14 @@ class TestRoutingMount < ActionDispatch::IntegrationTest
|
|||
def test_mounting_at_root_path
|
||||
get "/omg"
|
||||
assert_equal " -- /omg", response.body
|
||||
|
||||
get "/~omg"
|
||||
assert_equal " -- /~omg", response.body
|
||||
end
|
||||
|
||||
def test_mounting_at_path_with_non_word_character
|
||||
get "/star*/omg"
|
||||
assert_equal "/star* -- /omg", response.body
|
||||
end
|
||||
|
||||
def test_mounting_sets_script_name
|
||||
|
|
|
@ -34,17 +34,17 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
{
|
||||
"/: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)},
|
||||
"/: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