mirror of
https://github.com/ruby/ruby.git
synced 2025-08-26 06:25:31 +02:00
lib/webrick/httpservlet/filehandler.rb: always handle a path as UTF-8
20200618
T113134Z.fail.html.gz
```
1) Failure:
WEBrick::TestFileHandler#test_cjk_in_path [D:/tmp/mswin-build20200618-84004-1t0dh8f/ruby/test/webrick/utils.rb:72]:
exceptions on 2 threads:
webrick log start:
[2020-06-18 22:18:07] ERROR `/??.txt' not found.
webrick log end
Filesystem encoding is Windows-31J.
<"200"> expected but was
<"404">.
```
This commit is contained in:
parent
50c13eb718
commit
750203c514
2 changed files with 2 additions and 16 deletions
|
@ -36,17 +36,12 @@ module WEBrick
|
||||||
|
|
||||||
def initialize(server, local_path)
|
def initialize(server, local_path)
|
||||||
super(server, local_path)
|
super(server, local_path)
|
||||||
@local_path = local_path
|
@local_path = local_path.dup.force_encoding("UTF-8")
|
||||||
end
|
end
|
||||||
|
|
||||||
# :stopdoc:
|
# :stopdoc:
|
||||||
|
|
||||||
def do_GET(req, res)
|
def do_GET(req, res)
|
||||||
case enc = Encoding.find('filesystem')
|
|
||||||
when Encoding::US_ASCII, Encoding::ASCII_8BIT
|
|
||||||
else
|
|
||||||
@local_path = @local_path.dup.force_encoding(enc)
|
|
||||||
end
|
|
||||||
st = File::stat(@local_path)
|
st = File::stat(@local_path)
|
||||||
mtime = st.mtime
|
mtime = st.mtime
|
||||||
res['etag'] = sprintf("%x-%x-%x", st.ino, st.size, st.mtime.to_i)
|
res['etag'] = sprintf("%x-%x-%x", st.ino, st.size, st.mtime.to_i)
|
||||||
|
|
|
@ -294,16 +294,7 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
|
||||||
config = { :DocumentRoot => dir }
|
config = { :DocumentRoot => dir }
|
||||||
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)
|
||||||
filesystem_path = "\u3042"
|
req = Net::HTTP::Get.new("/%E3%81%82.txt")
|
||||||
case Encoding.find('filesystem')
|
|
||||||
when Encoding::US_ASCII, Encoding::ASCII_8BIT
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
filesystem_path = "\u3042".encode("filesystem")
|
|
||||||
rescue Encoding::UndefinedConversionError
|
|
||||||
end
|
|
||||||
end
|
|
||||||
req = Net::HTTP::Get.new("/#{ filesystem_path.bytes.map {|b| "%%%X" % b }.join }.txt")
|
|
||||||
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')}") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue