diff options
-rw-r--r-- | lib/fileutils.rb | 6 | ||||
-rw-r--r-- | test/fileutils/test_fileutils.rb | 17 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 438f3210f7..371a348159 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -1287,7 +1287,11 @@ module FileUtils 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 a72cb6bc96..8a546ccf1b 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -756,6 +756,23 @@ class TestFileUtils < Test::Unit::TestCase 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 |