diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb index 601882e..69adad2 100644 --- a/lib/webrick/httpservlet/filehandler.rb +++ b/lib/webrick/httpservlet/filehandler.rb @@ -324,7 +324,7 @@ def get_handler(req, res) end def set_filename(req, res) - res.filename = @root.dup + res.filename = @root.b path_info = req.path_info.scan(%r|/[^/]*|) path_info.unshift("") # dummy for checking @root dir diff --git a/test/webrick/test_filehandler.rb b/test/webrick/test_filehandler.rb index 33b6d7b..4d4963a 100644 --- a/test/webrick/test_filehandler.rb +++ b/test/webrick/test_filehandler.rb @@ -3,6 +3,7 @@ require_relative "utils.rb" require "webrick" require "stringio" +require "tmpdir" class WEBrick::TestFileHandler < Test::Unit::TestCase def teardown @@ -285,6 +286,18 @@ def test_short_filename end end + def test_cjk_in_path + Dir.mktmpdir("\u3042") do |dir| + File.write("#{dir}/\u3042.txt", "test_cjk_in_path") + config = { :DocumentRoot => dir } + TestWEBrick.start_httpserver(config) do |server, addr, port, log| + http = Net::HTTP.new(addr, port) + req = Net::HTTP::Get.new("/%E3%81%82.txt") + http.request(req){|res| assert_equal("200", res.code, log.call) } + end + end + end + def test_script_disclosure return if File.executable?(__FILE__) # skip on strange file system