Permalink
Browse files

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)

Conflicts:
	actionpack/CHANGELOG.md
  • Loading branch information...
1 parent 4249c33 commit 1193a2738dc751cedcd6155076d68c9851680317 @drogus drogus committed Jun 21, 2013
View
@@ -1228,4 +1228,6 @@
* `ActionView::Helpers::TextHelper#highlight` now defaults to the
HTML5 `mark` element. *Brian Cardarella*
+* Fix removing trailing slash for mounted apps #3215 *Piotr Sarnacki*
+
Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/actionpack/CHANGELOG.md) for previous changes.
@@ -54,7 +54,7 @@ def initialize(routes, options)
end
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|
script_name, path_info, set_params = env.values_at('SCRIPT_NAME',
@@ -103,6 +103,12 @@ def visualizer
private
+ def normalize_path(path)
+ path = "/#{path}"
+ path.squeeze!('/')
+ path
+ end
+
def partitioned_routes
routes.partitioned_routes
end
@@ -33,6 +33,11 @@ def app
Router
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
get "/sprockets/omg"
assert_equal "/sprockets -- /omg", response.body

1 comment on commit 1193a27

Owner

jeremy commented on 1193a27 Jun 21, 2013

This may have surprising ramifications. It probably doesn't belong on the 4.0 stable branch.

Please sign in to comment.