Project

General

Profile

Actions

Bug #3345

closed

webrick test failure on Windows(?)

Added by usa (Usaku NAKAMURA) almost 14 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.3dev (2010-05-26 trunk 28018) [i386-mswin32]
Backport:
[ruby-dev:41423]

Description

=begin
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

<TITLE>Internal Server Error</TITLE>\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
    =end
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0