From: Usaku NAKAMURA Date: 2010-05-26T18:45:51+09:00 Subject: [ruby-dev:41423] [Bug #3345] webrick test failure on Windows(?) Bug #3345: webrick test failure on Windows(?) http://redmine.ruby-lang.org/issues/show/3345 起票者: Usaku NAKAMURA ステータス: Open, 優先度: Normal カテゴリ: lib, Target version: 1.9.2 ruby -v: ruby 1.9.3dev (2010-05-26 trunk 28018) [i386-mswin32] webrickのテストが以下のように失敗します。 1) Failure: test_cgi(TestWEBrickCGI) [C:/ruby-trunk/test/webrick/test_cgi.rb:40]: webrick log start: [2010-05-26 17:32:08] INFO WEBrick 1.3.1 [2010-05-26 17:32:08] INFO ruby 1.9.3 (2010-05-26) [i386-mswin32] [2010-05-26 17:32:08] INFO WEBrick::HTTPServer#start: pid=6292 port=60199 [2010-05-26 17:32:08] WARN :RequestHandler is deprecated, please use :RequestCallback [2010-05-26 17:32:09] WARN :RequestHandler is deprecated, please use :RequestCallback [2010-05-26 17:32:11] WARN :RequestHandler is deprecated, please use :RequestCallback [2010-05-26 17:32:12] WARN :RequestHandler is deprecated, please use :RequestCallback [2010-05-26 17:32:12] ERROR Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and Windows-31J C:/ruby-trunk/lib/webrick/httpservlet/filehandler.rb:225:in `expand_path' C:/ruby-trunk/lib/webrick/httpservlet/filehandler.rb:225:in `prevent_directory_traversal' C:/ruby-trunk/lib/webrick/httpservlet/filehandler.rb:166:in `service' C:/ruby-trunk/lib/webrick/httpserver.rb:111:in `service' C:/ruby-trunk/lib/webrick/httpserver.rb:70:in `run' C:/ruby-trunk/lib/webrick/server.rb:183:in `block in start_thread' webrick log end. <"/\xA4\xDB\xA4\xB2/\xA4\xDB\xA4\xB2"> expected but was <"\n\n Internal Server Error\n \n

Internal Server Error

\n incompatible character encodings: ASCII-8BIT and Windows-31J\n
\n
\n WEBrick/1.3.1 (Ruby/1.9.3/2010-05-26) OpenSSL/1.0.0 at\n 127.0.0.1:60199\n
\n \n\n">. クライアントから渡された「/%A4%DB%A4%B2/%A4%DB%A4%B2」という パスを実ファイルシステムのパスに変換しようとしているわけですが、 (1) 「/%A4%DB%A4%B2/%A4%DB%A4%B2」をunescapeするとASCII-8BITになる (2) それをFile.expand_pathに渡すと、filesystem encodingであるはずの cwdとくっつけようとするのでエラーになる という話のようです。 というわけで、以下のパッチでいちおう直るんですが、話としては他の プラットフォームでも発生してしかるべき問題のような気がするのに、 どうも私しか踏んでないっぽいのはなぜでしょう? また、直し方としてはたしてこれでいいんでしょうか? どなたか教えてください。 Index: lib/webrick/httputils.rb =================================================================== --- lib/webrick/httputils.rb (revision 28018) +++ lib/webrick/httputils.rb (working copy) @@ -27,7 +27,7 @@ module WEBrick while ret.sub!(%r'/(?!\.\./)[^/]+/\.\.(?:/|\Z)', '/'); end # /foo/.. => /foo raise "abnormal path `#{path}'" if %r{/\.\.(/|\Z)} =~ ret - ret + ret.force_encoding(Encoding.find("filesystem")) end module_function :normalize_path ---------------------------------------- http://redmine.ruby-lang.org