From 6fe1919486111bcdd5ef41fea15b0e82f7f50d82 Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA Date: Fri, 19 Jun 2020 20:06:26 +0900 Subject: Fix failure on mswin CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://rubyci.org/logs/mswinci.japaneast.cloudapp.azure.com/vc12-x64/ruby-master/log/20200619T054159Z.fail.html.gz ``` 1) Failure: WEBrick::TestFileHandler#test_cjk_in_path [D:/tmp/mswin-build20200619-14304-utgij/ruby/test/webrick/utils.rb:72]: exceptions on 2 threads: webrick log start: [2020-06-19 16:28:42] ERROR `/あ.txt' not found. webrick log end Filesystem encoding is Windows-31J. <"200"> expected but was <"404">. --- <[]> expected but was <["[2020-06-19 16:28:42] ERROR `/\xE3\x81\x82.txt' not found.\n"]>. ``` `prevent_directory_traversal` treats `path_info` as filesystem encoding. So path_info should be filesystem encoding in request URL. On some environments, fallback to ASCII-8BIT when EncodingError. --- test/webrick/test_filehandler.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test/webrick') diff --git a/test/webrick/test_filehandler.rb b/test/webrick/test_filehandler.rb index edf0d8b12c..758ec7f589 100644 --- a/test/webrick/test_filehandler.rb +++ b/test/webrick/test_filehandler.rb @@ -294,7 +294,12 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase config = { :DocumentRoot => dir } TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) - req = Net::HTTP::Get.new("/%E3%81%82.txt") + begin + path = "/\u3042.txt".encode('filesystem') + rescue EncodingError + path = "/\u3042.txt".force_encoding(Encoding::ASCII_8BIT) + end + 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')}") } end end -- cgit v1.2.3