Skip to content

Fix empty SCRIPT_NAME with partial match route bug #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion lib/http_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def rewrite_partial_path_info(env, request)
env['PATH_INFO'] = "/"
env['SCRIPT_NAME'] += path_info_before
else
env['PATH_INFO'] = "/#{request.path.join('/')}"
env['PATH_INFO'] = "/#{URI.encode(request.path.join('/'))}"
env['SCRIPT_NAME'] += path_info_before[0, path_info_before.size - env['PATH_INFO'].size]
end
end
Expand Down
18 changes: 18 additions & 0 deletions test/rack/test_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,22 @@ def test_script_name_from_partial_match_of_single
router.call(Rack::MockRequest.env_for("/sidekiq"))
assert_equal('/sidekiq', request_env['SCRIPT_NAME'])
end

def test_path_info_with_encoded_request_path
request_env = nil
router do
add("/sidekiq*").to { |env| request_env = env; [200, {}, []] }
end
router.call(Rack::MockRequest.env_for("/sidekiq/queues/some%20path"))
assert_equal('/queues/some%20path', request_env['PATH_INFO'])
end

def test_script_name_with_encoded_request_path
request_env = nil
router do
add("/sidekiq*").to { |env| request_env = env; [200, {}, []] }
end
router.call(Rack::MockRequest.env_for("/sidekiq/queues/some%20path"))
assert_equal('/sidekiq', request_env['SCRIPT_NAME'])
end
end