[前][次][番号順一覧][スレッド一覧]

ruby-changes:61892

From: Kazuhiro <ko1@a...>
Date: Mon, 22 Jun 2020 18:06:05 +0900 (JST)
Subject: [ruby-changes:61892] 3238641750 (master): Use filesystem encoding for file path only

https://git.ruby-lang.org/ruby.git/commit/?id=3238641750

From 3238641750c1f6d9e6be5d74fadc53e512638fe2 Mon Sep 17 00:00:00 2001
From: Kazuhiro NISHIYAMA <zn@m...>
Date: Mon, 22 Jun 2020 17:37:37 +0900
Subject: Use filesystem encoding for file path only

`path_info` contains filesystem encoding and binary.
Example is `"/webrick.cgi/%A5%DB%A4%B2/%A4%DB%A4%B2"` in `TestWEBrickCGI#test_cgi`.

diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb
index 41c0618..010df0e 100644
--- a/lib/webrick/httpservlet/filehandler.rb
+++ b/lib/webrick/httpservlet/filehandler.rb
@@ -213,10 +213,11 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpservlet/filehandler.rb#L213
       # :stopdoc:
 
       def set_filesystem_encoding(str)
-        if Encoding.find('filesystem') == Encoding::US_ASCII
+        enc = Encoding.find('filesystem')
+        if enc == Encoding::US_ASCII
           str.b
         else
-          str.dup.force_encoding('filesystem')
+          str.dup.force_encoding(enc)
         end
       end
 
@@ -333,10 +334,11 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpservlet/filehandler.rb#L334
 
       def set_filename(req, res)
         res.filename = @root
-        path_info = req.path_info.scan(%r|/[^/]*|).map{|path| set_filesystem_encoding(path) }
+        path_info = req.path_info.scan(%r|/[^/]*|)
 
         path_info.unshift("")  # dummy for checking @root dir
         while base = path_info.first
+          base = set_filesystem_encoding(base)
           break if base == "/"
           break unless File.directory?(File.expand_path(res.filename + base))
           shift_path_info(req, res, path_info)
@@ -344,6 +346,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpservlet/filehandler.rb#L346
         end
 
         if base = path_info.first
+          base = set_filesystem_encoding(base)
           if base == "/"
             if file = search_index_file(req, res)
               shift_path_info(req, res, path_info, file)
@@ -372,7 +375,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpservlet/filehandler.rb#L375
 
       def shift_path_info(req, res, path_info, base=nil)
         tmp = path_info.shift
-        base = base || tmp
+        base = base || set_filesystem_encoding(tmp)
         req.path_info = path_info.join
         req.script_name << base
         res.filename = File.expand_path(res.filename + base)
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]