Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Commit a92f89d

Browse files
committed
Merge pull request #2 from Acornsgrow/handle_escaping_of_path
Add URI encoding for path info
2 parents 1706d40 + 1f96735 commit a92f89d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/http_router.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def rewrite_partial_path_info(env, request)
225225
env['PATH_INFO'] = "/"
226226
env['SCRIPT_NAME'] += path_info_before
227227
else
228-
env['PATH_INFO'] = "/#{request.path.join('/')}"
228+
env['PATH_INFO'] = "/#{URI.encode(request.path.join('/'))}"
229229
env['SCRIPT_NAME'] += path_info_before[0, path_info_before.size - env['PATH_INFO'].size]
230230
end
231231
end

test/rack/test_route.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,22 @@ def test_script_name_from_partial_match_of_single
7272
router.call(Rack::MockRequest.env_for("/sidekiq"))
7373
assert_equal('/sidekiq', request_env['SCRIPT_NAME'])
7474
end
75+
76+
def test_path_info_with_encoded_request_path
77+
request_env = nil
78+
router do
79+
add("/sidekiq*").to { |env| request_env = env; [200, {}, []] }
80+
end
81+
router.call(Rack::MockRequest.env_for("/sidekiq/queues/some%20path"))
82+
assert_equal('/queues/some%20path', request_env['PATH_INFO'])
83+
end
84+
85+
def test_script_name_with_encoded_request_path
86+
request_env = nil
87+
router do
88+
add("/sidekiq*").to { |env| request_env = env; [200, {}, []] }
89+
end
90+
router.call(Rack::MockRequest.env_for("/sidekiq/queues/some%20path"))
91+
assert_equal('/sidekiq', request_env['SCRIPT_NAME'])
92+
end
7593
end

0 commit comments

Comments
 (0)