Skip to content

Commit

Permalink
[ruby/webrick] Fix httpd error in CJK directory
Browse files Browse the repository at this point in the history
  • Loading branch information
znz authored and hsbt committed Jun 11, 2020
1 parent 6742fcf commit e698bf1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/webrick/httpservlet/filehandler.rb
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/webrick/test_filehandler.rb
Expand Up @@ -3,6 +3,7 @@
require_relative "utils.rb"
require "webrick"
require "stringio"
require "tmpdir"

class WEBrick::TestFileHandler < Test::Unit::TestCase
def teardown
Expand Down Expand Up @@ -287,6 +288,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

Expand Down

0 comments on commit e698bf1

Please sign in to comment.