Skip to content

Commit

Permalink
Use filesystem encoding in do_GET of filehandler
Browse files Browse the repository at this point in the history
Try to fix 404 error on mswinci.

https://rubyci.org/logs/mswinci.japaneast.cloudapp.azure.com/vc12-x64/ruby-master/log/20200614T225859Z.fail.html.gz
```
  1) Failure:
WEBrick::TestFileHandler#test_cjk_in_path [D:/tmp/mswin-build20200615-24932-11ykstf/ruby/test/webrick/utils.rb:72]:
exceptions on 2 threads:
webrick log start:
  [2020-06-15 09:48:29] ERROR `/あ.txt' not found.

webrick log end.
<"200"> expected but was
<"404">.
---
<[]> expected but was
<["[2020-06-15 09:48:29] ERROR `/\xE3\x81\x82.txt' not found.\n"]>.
```
  • Loading branch information
znz committed Jun 15, 2020
1 parent 80bd3aa commit 93e6fa1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/webrick/httpservlet/filehandler.rb
Expand Up @@ -42,6 +42,11 @@ def initialize(server, local_path)
# :stopdoc:

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)
mtime = st.mtime
res['etag'] = sprintf("%x-%x-%x", st.ino, st.size, st.mtime.to_i)
Expand Down

0 comments on commit 93e6fa1

Please sign in to comment.