mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't remove trailing slash from PATH_INFO for mounted apps
Previously when app was mounted as following: class Foo def call(env) [200, {}, [env['PATH_INFO']]] end end RackMountRailsBug::Application.routes.draw do mount RackTest.new => "/foo" end trailing slash was removed from PATH_INFO. For example requesting GET /foo/bar/ on routes defined above would result in a response containing "/foo/bar" instead of "/foo/bar/". This commit fixes the issue. (closes #3215)
This commit is contained in:
parent
5ac22989d3
commit
50311f1391
3 changed files with 16 additions and 1 deletions
|
@ -2,4 +2,8 @@
|
||||||
|
|
||||||
*Piotr Sarnacki*, *Łukasz Strzałkowski*
|
*Piotr Sarnacki*, *Łukasz Strzałkowski*
|
||||||
|
|
||||||
|
* Fix removing trailing slash for mounted apps #3215
|
||||||
|
|
||||||
|
*Piotr Sarnacki*
|
||||||
|
|
||||||
Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/actionpack/CHANGELOG.md) for previous changes.
|
Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/actionpack/CHANGELOG.md) for previous changes.
|
||||||
|
|
|
@ -54,7 +54,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
env['PATH_INFO'] = Utils.normalize_path(env['PATH_INFO'])
|
env['PATH_INFO'] = normalize_path(env['PATH_INFO'])
|
||||||
|
|
||||||
find_routes(env).each do |match, parameters, route|
|
find_routes(env).each do |match, parameters, route|
|
||||||
script_name, path_info, set_params = env.values_at('SCRIPT_NAME',
|
script_name, path_info, set_params = env.values_at('SCRIPT_NAME',
|
||||||
|
@ -103,6 +103,12 @@ module ActionDispatch
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def normalize_path(path)
|
||||||
|
path = "/#{path}"
|
||||||
|
path.squeeze!('/')
|
||||||
|
path
|
||||||
|
end
|
||||||
|
|
||||||
def partitioned_routes
|
def partitioned_routes
|
||||||
routes.partitioned_routes
|
routes.partitioned_routes
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,11 @@ class TestRoutingMount < ActionDispatch::IntegrationTest
|
||||||
Router
|
Router
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_trailing_slash_is_not_removed_from_path_info
|
||||||
|
get "/sprockets/omg/"
|
||||||
|
assert_equal "/sprockets -- /omg/", response.body
|
||||||
|
end
|
||||||
|
|
||||||
def test_mounting_sets_script_name
|
def test_mounting_sets_script_name
|
||||||
get "/sprockets/omg"
|
get "/sprockets/omg"
|
||||||
assert_equal "/sprockets -- /omg", response.body
|
assert_equal "/sprockets -- /omg", response.body
|
||||||
|
|
Loading…
Reference in a new issue