mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add tests of nested multibyte path and DirectoryIndex
This commit is contained in:
parent
d231b8f95b
commit
61743f0c83
1 changed files with 23 additions and 13 deletions
|
@ -289,23 +289,33 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multibyte_char_in_path
|
def test_multibyte_char_in_path
|
||||||
Dir.mktmpdir("\u00a7") do |dir|
|
c = "\u00a7"
|
||||||
File.write("#{dir}/\u00a7.txt", "test_multibyte_char_in_path")
|
|
||||||
begin
|
begin
|
||||||
dir = dir.encode('filesystem')
|
c = c.encode('filesystem')
|
||||||
rescue EncodingError
|
rescue EncodingError
|
||||||
dir = dir.b
|
c = c.b
|
||||||
end
|
end
|
||||||
config = { :DocumentRoot => dir }
|
Dir.mktmpdir(c) do |dir|
|
||||||
|
basename = "#{c}.txt"
|
||||||
|
File.write("#{dir}/#{basename}", "test_multibyte_char_in_path")
|
||||||
|
Dir.mkdir("#{dir}/#{c}")
|
||||||
|
File.write("#{dir}/#{c}/#{basename}", "nested")
|
||||||
|
config = {
|
||||||
|
:DocumentRoot => dir,
|
||||||
|
:DirectoryIndex => [basename],
|
||||||
|
}
|
||||||
TestWEBrick.start_httpserver(config) do |server, addr, port, log|
|
TestWEBrick.start_httpserver(config) do |server, addr, port, log|
|
||||||
http = Net::HTTP.new(addr, port)
|
http = Net::HTTP.new(addr, port)
|
||||||
begin
|
path = "/#{basename}"
|
||||||
path = "/\u00a7.txt".encode('filesystem')
|
|
||||||
rescue EncodingError
|
|
||||||
path = "/\u00a7.txt".force_encoding(Encoding::ASCII_8BIT)
|
|
||||||
end
|
|
||||||
req = Net::HTTP::Get.new(WEBrick::HTTPUtils::escape(path))
|
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')}") }
|
http.request(req){|res| assert_equal("200", res.code, log.call + "\nFilesystem encoding is #{Encoding.find('filesystem')}") }
|
||||||
|
path = "/#{c}/#{basename}"
|
||||||
|
req = Net::HTTP::Get.new(WEBrick::HTTPUtils::escape(path))
|
||||||
|
http.request(req){|res| assert_equal("200", res.code, log.call) }
|
||||||
|
req = Net::HTTP::Get.new('/')
|
||||||
|
http.request(req){|res|
|
||||||
|
assert_equal("test_multibyte_char_in_path", res.body, log.call)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue