Skip to content

Commit 0da851a

Browse files
znzhsbt
authored andcommitted
Fix Encoding::CompatibilityError in FileUtils::Entry_#join
1 parent 57fbf9a commit 0da851a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/fileutils.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,15 @@ def check_have_lchown?
15591559
def join(dir, base)
15601560
return File.path(dir) if not base or base == '.'
15611561
return File.path(base) if not dir or dir == '.'
1562-
File.join(dir, base)
1562+
begin
1563+
File.join(dir, base)
1564+
rescue EncodingError
1565+
if fu_windows?
1566+
File.join(dir.encode(::Encoding::UTF_8), base.encode(::Encoding::UTF_8))
1567+
else
1568+
raise
1569+
end
1570+
end
15631571
end
15641572

15651573
if File::ALT_SEPARATOR

test/fileutils/test_fileutils.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,6 @@ def test_remove_entry_multibyte_path
771771

772772
remove_entry dir
773773
assert_file_not_exist dir
774-
rescue MiniTest::Assertion
775-
STDERR.puts Dir.glob("#{dir}/**/*").inspect
776-
raise
777774
end
778775

779776
def test_remove_entry_secure

0 commit comments

Comments
 (0)