Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix to not allow trailing slash on script name when matching

This is related to a Rails issue with mounted engines on root path.
See issues:

rails/rails#2131
rails/rails#2230
rails/rails#2579
rails/rails#5342
  • Loading branch information...
commit 61ddc45c07c2b946a725bbdca8ef8adcd9ff1afc 1 parent 805efa6
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 22 additions and 10 deletions.
  1. +1 −1  lib/journey/router.rb
  2. +21 −9 test/test_router.rb
View
2  lib/journey/router.rb
@@ -59,7 +59,7 @@ def call env
@params_key)
unless route.path.anchored
- env['SCRIPT_NAME'] = script_name.to_s + match.to_s
+ env['SCRIPT_NAME'] = (script_name.to_s + match.to_s).chomp('/')
env['PATH_INFO'] = match.post_match
end
View
30 test/test_router.rb
@@ -51,9 +51,9 @@ def test_dashes
def test_unicode
router = Router.new(routes, {})
-
+
#match the escaped version of /ほげ
- exp = Router::Strexp.new '/%E3%81%BB%E3%81%92', {}, ['/.?']
+ exp = Router::Strexp.new '/%E3%81%BB%E3%81%92', {}, ['/.?']
path = Path::Pattern.new exp
routes.add_route nil, path, {}, {:id => nil}, {}
@@ -195,6 +195,18 @@ def test_X_Cascade
assert_equal 404, resp.first
end
+ def test_clear_trailing_slash_from_script_name_on_root_unanchored_routes
+ strexp = Router::Strexp.new("/", {}, ['/', '.', '?'], false)
+ path = Path::Pattern.new strexp
+ app = lambda { |env| [200, {}, ['success!']] }
+ route = @router.routes.add_route(app, path, {}, {}, {})
+
+ env = rack_env('SCRIPT_NAME' => '', 'PATH_INFO' => '/weblog')
+ resp = @router.call(env)
+ assert_equal ['success!'], resp.last
+ assert_equal '', env['SCRIPT_NAME']
+ end
+
def test_defaults_merge_correctly
path = Path::Pattern.new '/foo(/:id)'
@router.routes.add_route nil, path, {}, {:id => nil}, {}
@@ -278,13 +290,6 @@ def test_recall_should_be_used_when_scoring
assert_equal "/messages/index/10", path
end
- def add_routes router, paths
- paths.each do |path|
- path = Path::Pattern.new path
- router.routes.add_route nil, path, {}, {}, {}
- end
- end
-
def test_nil_path_parts_are_ignored
path = Path::Pattern.new "/:controller(/:action(.:format))"
@router.routes.add_route nil, path, {}, {}, {}
@@ -499,6 +504,13 @@ def test_recognize_cares_about_verbs
private
+ def add_routes router, paths
+ paths.each do |path|
+ path = Path::Pattern.new path
+ router.routes.add_route nil, path, {}, {}, {}
+ end
+ end
+
RailsEnv = Struct.new(:env)
def rails_env env
Please sign in to comment.
Something went wrong with that request. Please try again.