win32: Use UTF-8 as filesystem encoding [Feature #12654]

Co-Authored-By: Dāvis Mosāns <davispuh@gmail.com>
This commit is contained in:
Nobuyoshi Nakada 2020-12-20 02:16:31 +09:00
parent feea436feb
commit 5b98b2ce39
Notes: git 2020-12-20 18:34:28 +09:00
6 changed files with 37 additions and 59 deletions

View file

@ -17,27 +17,19 @@ class TestDir_M17N < Test::Unit::TestCase
assert_separately(["-E#{encoding}"], <<-EOS, :chdir=>dir)
filename = #{code}.chr('UTF-8').force_encoding("#{encoding}")
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", **(opts||{}))
ents = Dir.entries(".")
if /mswin|mingw/ =~ RUBY_PLATFORM
filename = filename.encode("UTF-8")
end
assert_include(ents, filename)
EOS
return if /cygwin/ =~ RUBY_PLATFORM
assert_separately(%w[-EASCII-8BIT], <<-EOS, :chdir=>dir)
filename = #{code}.chr('UTF-8').force_encoding("ASCII-8BIT")
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", **(opts||{}))
expected_filename = #{code}.chr('UTF-8').encode(Encoding.find("filesystem")) rescue expected_filename = "?"
expected_filename = expected_filename.force_encoding("ASCII-8BIT")
ents = Dir.entries(".")
if /mswin|mingw/ =~ RUBY_PLATFORM
case
when ents.include?(filename)
when ents.include?(expected_filename)
filename = expected_filename
else
ents = Dir.entries(".", :encoding => Encoding.find("filesystem"))
filename = expected_filename
end
filename.force_encoding("UTF-8")
end
assert_include(ents, filename)
EOS
@ -199,27 +191,23 @@ class TestDir_M17N < Test::Unit::TestCase
assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d)
filename = "\xA4\xA2".force_encoding("euc-jp")
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", **(opts||{}))
ents = Dir.entries(".")
if /darwin/ =~ RUBY_PLATFORM
filename = filename.encode("utf-8").force_encoding("euc-jp")
elsif /mswin|mingw/ =~ RUBY_PLATFORM
filename = filename.encode("utf-8")
end
assert_include(ents, filename)
EOS
assert_separately(%w[-EASCII-8BIT], <<-'EOS', :chdir=>d)
filename = "\xA4\xA2".force_encoding('ASCII-8BIT')
win_expected_filename = filename.encode(Encoding.find("filesystem"), "euc-jp") rescue "?"
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", **(opts||{}))
ents = Dir.entries(".")
unless ents.include?(filename)
case RUBY_PLATFORM
when /darwin/
filename = filename.encode("utf-8", "euc-jp").b
when /mswin|mingw/
if ents.include?(win_expected_filename.b)
ents = Dir.entries(".", :encoding => Encoding.find("filesystem"))
filename = win_expected_filename
end
filename = filename.encode("utf-8", "euc-jp")
end
end
assert_include(ents, filename)
@ -414,13 +402,8 @@ class TestDir_M17N < Test::Unit::TestCase
orig.each {|n| open(n, "w") {}}
enc = Encoding.find("filesystem")
enc = Encoding::ASCII_8BIT if enc == Encoding::US_ASCII
if /mswin|mingw/ =~ RUBY_PLATFORM
opts = {:encoding => enc}
orig.map! {|o| o.encode("filesystem") rescue o.tr("^a-z", "?")}
else
orig.each {|o| o.force_encoding(enc) }
end
ents = Dir.entries(".", **(opts||{})).reject {|n| /\A\./ =~ n}
orig.each {|o| o.force_encoding(enc) }
ents = Dir.entries(".").reject {|n| /\A\./ =~ n}
ents.sort!
PP.assert_equal(orig, ents, bug7267)
}
@ -431,13 +414,9 @@ class TestDir_M17N < Test::Unit::TestCase
expected = []
results = []
orig.each {|o|
if /mswin|mingw/ =~ RUBY_PLATFORM
n = (o.encode("filesystem") rescue next)
else
enc = Encoding.find("filesystem")
enc = Encoding::ASCII_8BIT if enc == Encoding::US_ASCII
n = o.dup.force_encoding(enc)
end
enc = Encoding.find("filesystem")
enc = Encoding::ASCII_8BIT if enc == Encoding::US_ASCII
n = o.dup.force_encoding(enc)
expected << n
with_tmpdir {
Dir.mkdir(o)