Used URI_INSTANCE unescape method instead of wild unescape function in the static files path computation
This commit is contained in:
parent
f9446dfc02
commit
5beba64731
|
@ -1034,7 +1034,7 @@ module Sinatra
|
|||
# a matching file is found, returns nil otherwise.
|
||||
def static!(options = {})
|
||||
return if (public_dir = settings.public_folder).nil?
|
||||
path = File.expand_path("#{public_dir}#{unescape(request.path_info)}" )
|
||||
path = File.expand_path("#{public_dir}#{URI_INSTANCE.unescape(request.path_info)}" )
|
||||
return unless File.file?(path)
|
||||
|
||||
env['sinatra.static_file'] = path
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
This is a test intended for the + sign in urls for static serving
|
|
@ -233,4 +233,34 @@ class StaticTest < Minitest::Test
|
|||
assert response.headers.include?('Last-Modified')
|
||||
end
|
||||
|
||||
it 'serves files with a + sign in the path' do
|
||||
mock_app do
|
||||
set :static, true
|
||||
set :public_folder, File.join(File.dirname(__FILE__), 'public')
|
||||
end
|
||||
|
||||
get "/hello+world.txt"
|
||||
|
||||
real_path = File.join(File.dirname(__FILE__), 'public', 'hello+world.txt')
|
||||
assert ok?
|
||||
assert_equal File.read(real_path), body
|
||||
assert_equal File.size(real_path).to_s, response['Content-Length']
|
||||
assert response.headers.include?('Last-Modified')
|
||||
end
|
||||
|
||||
it 'serves files with a URL encoded + sign (%2B) in the path' do
|
||||
mock_app do
|
||||
set :static, true
|
||||
set :public_folder, File.join(File.dirname(__FILE__), 'public')
|
||||
end
|
||||
|
||||
get "/hello%2bworld.txt"
|
||||
|
||||
real_path = File.join(File.dirname(__FILE__), 'public', 'hello+world.txt')
|
||||
assert ok?
|
||||
assert_equal File.read(real_path), body
|
||||
assert_equal File.size(real_path).to_s, response['Content-Length']
|
||||
assert response.headers.include?('Last-Modified')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue