ruby-changes:61890
From: Kazuhiro <ko1@a...>
Date: Mon, 22 Jun 2020 17:12:06 +0900 (JST)
Subject: [ruby-changes:61890] d231b8f95b (master): Fix remove_entry error when path encoding is not compatible UTF-8
https://git.ruby-lang.org/ruby.git/commit/?id=d231b8f95b From d231b8f95b35d8a344cec4f62d7bbdf360a70e1c Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA <zn@m...> Date: Mon, 22 Jun 2020 17:07:49 +0900 Subject: Fix remove_entry error when path encoding is not compatible UTF-8 diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 438f321..371a348 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -1287,7 +1287,11 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1287 def entries opts = {} - opts[:encoding] = fu_windows? ? ::Encoding::UTF_8 : path.encoding + if fu_windows? && ::Encoding.compatible?(::Encoding::UTF_8, path.encoding) + opts[:encoding] = ::Encoding::UTF_8 + else + opts[:encoding] = path.encoding + end files = if Dir.respond_to?(:children) Dir.children(path, **opts) diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index a72cb6bc..8a546cc 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -756,6 +756,23 @@ class TestFileUtils < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L756 assert_file_not_exist dir end + def test_remove_entry_multibyte_path + c = "\u00a7" + begin + c = c.encode('filesystem') + rescue EncodingError + c = c.b + end + dir = "tmpdir#{c}" + my_rm_rf dir + + Dir.mkdir dir + File.write("#{dir}/#{c}.txt", "test_remove_entry_multibyte_path") + + remove_entry dir + assert_file_not_exist dir + end + def test_remove_entry_secure check_singleton :remove_entry_secure -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/