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

ruby-changes:61893

From: Kazuhiro <ko1@a...>
Date: Mon, 22 Jun 2020 18:06:05 +0900 (JST)
Subject: [ruby-changes:61893] 61743f0c83 (master): Add tests of nested multibyte path and DirectoryIndex

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

From 61743f0c830498cba3c098a3d9e38644b159c563 Mon Sep 17 00:00:00 2001
From: Kazuhiro NISHIYAMA <zn@m...>
Date: Mon, 22 Jun 2020 17:31:07 +0900
Subject: Add tests of nested multibyte path and DirectoryIndex


diff --git a/test/webrick/test_filehandler.rb b/test/webrick/test_filehandler.rb
index fca073d..1114af3 100644
--- a/test/webrick/test_filehandler.rb
+++ b/test/webrick/test_filehandler.rb
@@ -289,23 +289,33 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/webrick/test_filehandler.rb#L289
   end
 
   def test_multibyte_char_in_path
-    Dir.mktmpdir("\u00a7") do |dir|
-      File.write("#{dir}/\u00a7.txt", "test_multibyte_char_in_path")
-      begin
-        dir = dir.encode('filesystem')
-      rescue EncodingError
-        dir = dir.b
-      end
-      config = { :DocumentRoot => dir }
+    c = "\u00a7"
+    begin
+      c = c.encode('filesystem')
+    rescue EncodingError
+      c = c.b
+    end
+    Dir.mktmpdir(c) do |dir|
+      basename = "#{c}.txt"
+      File.write("#{dir}/#{basename}", "test_multibyte_char_in_path")
+      Dir.mkdir("#{dir}/#{c}")
+      File.write("#{dir}/#{c}/#{basename}", "nested")
+      config = {
+        :DocumentRoot => dir,
+        :DirectoryIndex => [basename],
+      }
       TestWEBrick.start_httpserver(config) do |server, addr, port, log|
         http = Net::HTTP.new(addr, port)
-        begin
-          path = "/\u00a7.txt".encode('filesystem')
-        rescue EncodingError
-          path = "/\u00a7.txt".force_encoding(Encoding::ASCII_8BIT)
-        end
+        path = "/#{basename}"
         req = Net::HTTP::Get.new(WEBrick::HTTPUtils::escape(path))
         http.request(req){|res| assert_equal("200", res.code, log.call + "\nFilesystem encoding is #{Encoding.find('filesystem')}") }
+        path = "/#{c}/#{basename}"
+        req = Net::HTTP::Get.new(WEBrick::HTTPUtils::escape(path))
+        http.request(req){|res| assert_equal("200", res.code, log.call) }
+        req = Net::HTTP::Get.new('/')
+        http.request(req){|res|
+          assert_equal("test_multibyte_char_in_path", res.body, log.call)
+        }
       end
     end
   end
-- 
cgit v0.10.2


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

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