From: Yusuke Endoh Date: 2010-06-16T03:13:55+09:00 Subject: [ruby-dev:41615] [Bug #3345] webrick test failure on Windows(?) チケット #3345 が更新されました。 (by Yusuke Endoh) 担当者 Usaku NAKAMURAにセット 遠藤です。 > というわけで、以下のパッチでいちおう直るんですが、話としては他の > プラットフォームでも発生してしかるべき問題のような気がするのに、 > どうも私しか踏んでないっぽいのはなぜでしょう? File.expand_path("/webrick.cgi/\xA4\xDB\xA4\xB2/\xA4\xDB\xA4\xB2".force_encoding("ASCII-8BIT")) のようなことが実行されていて、先頭が / で始まっているため、Linux など だと特に何もしないけれど、Windows だと何か (ドライブレター?) を足そう とするため落ちるのかと思います。 unak さんのパッチだと、Linux でエラーが発生するようになりました。 filesystem encoding は UTF-8 ですが、このパスは UTF-8 として invalid なので、=~ で正規表現マッチができないことが原因です。 1) Failure: test_cgi(TestWEBrickCGI) [/home/mame/work/ruby/test/webrick/test_cgi.rb:40]: webrick log start: [2010-06-16 02:48:55] INFO WEBrick 1.3.1 [2010-06-16 02:48:55] INFO ruby 1.9.3 (2010-06-16) [i686-linux] [2010-06-16 02:48:55] INFO WEBrick::HTTPServer#start: pid=15315 port=38912 [2010-06-16 02:48:55] WARN :RequestHandler is deprecated, please use :RequestCallback [2010-06-16 02:48:55] WARN :RequestHandler is deprecated, please use :RequestCallback [2010-06-16 02:48:55] WARN :RequestHandler is deprecated, please use :RequestCallback [2010-06-16 02:48:55] WARN :RequestHandler is deprecated, please use :RequestCallback [2010-06-16 02:48:55] ERROR ArgumentError: invalid byte sequence in UTF-8 /home/mame/work/ruby/lib/webrick/httpserver.rb:196:in `=~' /home/mame/work/ruby/lib/webrick/httpserver.rb:196:in `scan' /home/mame/work/ruby/lib/webrick/httpserver.rb:136:in `search_servlet' /home/mame/work/ruby/lib/webrick/httpserver.rb:105:in `service' /home/mame/work/ruby/lib/webrick/httpserver.rb:70:in `run' /home/mame/work/ruby/lib/webrick/server.rb:183:in `block in start_thread' prevent_directory_traversal の問題を正確に理解していないのですが、 問題がおきるのが Windows だけで、\\ の扱いだけの問題だとしたら、 File.expand_path を使わず gsub で処理するといいのではないでしょう か。 diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb index 32c1965..50bf27c 100644 --- a/lib/webrick/httpservlet/filehandler.rb +++ b/lib/webrick/httpservlet/filehandler.rb @@ -214,17 +214,13 @@ module WEBrick # character in URI notation. So the value of path_info should be # normalize before accessing to the filesystem. - if trailing_pathsep?(req.path_info) - # File.expand_path removes the trailing path separator. - # Adding a character is a workaround to save it. - # File.expand_path("/aaa/") #=> "/aaa" - # File.expand_path("/aaa/" + "x") #=> "/aaa/x" - expanded = File.expand_path(req.path_info + "x") - expanded.chop! # remove trailing "x" - else - expanded = File.expand_path(req.path_info) + is_windows = RUBY_PLATFORM =~ /mswin/ || + RUBY_PLATFORM =~ /mingw/ || + RUBY_PLATFORM =~ /bccwin/ || + RUBY_PLATFORM =~ /wince/ + if is_windows + req.path_info = req.path_info.gsub("\\", "/") end - req.path_info = expanded end def exec_handler(req, res) -- Yusuke Endoh ---------------------------------------- http://redmine.ruby-lang.org/issues/show/3345 ---------------------------------------- http://redmine.ruby-lang.org