diff options
-rw-r--r-- | lib/webrick/httpservlet/filehandler.rb | 11 | ||||
-rw-r--r-- | test/webrick/test_filehandler.rb | 7 |
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb index 06d1a3067d..f41a5b07cf 100644 --- a/lib/webrick/httpservlet/filehandler.rb +++ b/lib/webrick/httpservlet/filehandler.rb @@ -324,8 +324,17 @@ module WEBrick end def set_filename(req, res) - res.filename = @root.b + res.filename = @root path_info = req.path_info.scan(%r|/[^/]*|) + begin + path_info.map! do |path| + path.force_encoding('filesystem').encode(@root.encoding) + end + rescue EncodingError + path_info.map! do |path| + path.force_encoding(@root.encoding) + end + end path_info.unshift("") # dummy for checking @root dir while base = path_info.first diff --git a/test/webrick/test_filehandler.rb b/test/webrick/test_filehandler.rb index edf0d8b12c..758ec7f589 100644 --- a/test/webrick/test_filehandler.rb +++ b/test/webrick/test_filehandler.rb @@ -294,7 +294,12 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase 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") + begin + path = "/\u3042.txt".encode('filesystem') + rescue EncodingError + path = "/\u3042.txt".force_encoding(Encoding::ASCII_8BIT) + end + req = Net::HTTP::Get.new(WEBrick::HTTPUtils::escape(path)) http.request(req){|res| assert_equal("200", res.code, log.call + "\nFilesystem encoding is #{Encoding.find('filesystem')}") } end end |