Project

General

Profile

Backport #7294 ยป 0001-backport-bug-6765.diff

luislavena (Luis Lavena), 11/07/2012 04:55 AM

View differences:

ChangeLog
Tue Jul 24 12:13:26 2012 NAKAMURA Usaku <usa@ruby-lang.org>
* test/ruby/test_dir_m17n.rb: refactoring. RE should be in the left side
of the =~ operator, and compare the result with nil is meaningless.
Tue Jul 24 08:30:15 2012 Luis Lavena <luislavena@gmail.com>
* test/ruby/test_dir_m17n.rb (create_and_check_raw_file_name): add new
helper method to ease encoding testing. Patch by Oleg Sukhodolsky.
[ruby-core:46589][Bug #6765]
* test/ruby/test_dir_m17n.rb (test_filename_extutf8): use filesystem
encoding when reading entries and comparing.
* test/ruby/test_dir_m17n.rb (test_filename_utf8_raw_name): removed.
* test/ruby/test_dir_m17n.rb (test_filename_utf8_raw_jp_name): split test.
Fri Oct 26 17:22:18 2012 NAKAMURA Usaku <usa@ruby-lang.org>
* file.c (append_fspath): need to set the encoding to result always.
test/ruby/test_dir_m17n.rb
}
end
def create_and_check_raw_file_name(code, encoding)
with_tmpdir { |dir|
create_file_program = %Q[
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)
exit ents.include?(filename)
]
assert_ruby_status(["-E#{encoding}"], create_file_program, nil, :chdir=>dir)
test_file_program = %Q[
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")
result = ents.include?(filename) || (/mswin|mingw/ =~ RUBY_PLATFORM && ents.include?(expected_filename))
if !result && /mswin|mingw/ =~ RUBY_PLATFORM
exit Dir.entries(".", {:encoding => Encoding.find("filesystem")}).include?(expected_filename)
end
exit result
]
assert_ruby_status(%w[-EASCII-8BIT], test_file_program, nil, :chdir=>dir)
}
end
## UTF-8 default_external, no default_internal
def test_filename_extutf8
......
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts)
exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%FF"))
exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%FF"))
EOS
assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d)
filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts)
exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%FF"))
exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%FF"))
EOS
}
end unless /mswin|mingw/ =~ RUBY_PLATFORM
......
ents = Dir.entries(".", opts)
ents.each {|e| e.force_encoding("ASCII-8BIT") }
exit ents.include?(filename.force_encoding("ASCII-8BIT")) ||
((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("ASCII-8BIT")))
(/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2".force_encoding("ASCII-8BIT")))
EOS
}
end
......
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts)
exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("euc-jp")))
exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2".force_encoding("euc-jp")))
EOS
assert_ruby_status(%w[-EASCII-8BIT], <<-'EOS', nil, :chdir=>d)
filename = "\xA4\xA2"
filename = "\xA4\xA2".force_encoding('ASCII-8BIT')
win_expected_filename = filename.encode(Encoding.find("filesystem")) rescue "?"
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts)
exit ents.include?(filename) ||
((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("ASCII-8BIT"))) ||
((RUBY_PLATFORM =~ /mswin|mingw/) != nil && ents.include?("\x82\xA0".force_encoding("ASCII-8BIT")))
p ents
result = ents.include?(filename) ||
(/darwin/ =~ RUBY_PLATFORM =~ /darwin/ && ents.include?("%A4%A2".force_encoding("ASCII-8BIT"))) ||
(/mswin|mingw/ =~ RUBY_PLATFORM && ents.include?(win_expected_filename.force_encoding("ASCII-8BIT")))
if !result && /mswin|mingw/ =~ RUBY_PLATFORM
exit Dir.entries(".", {:encoding => Encoding.find("filesystem")}).include?(win_expected_filename)
end
exit result
EOS
}
end
def test_filename_utf8_raw_name
with_tmpdir {|d|
assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d)
filename = "\u3042".force_encoding("utf-8")
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts)
exit ents.include?(filename)
EOS
assert_ruby_status(%w[-EASCII-8BIT], <<-'EOS', nil, :chdir=>d)
filename = "\u3042".force_encoding("ASCII-8BIT")
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts)
exit ents.include?(filename) || ((RUBY_PLATFORM =~ /mswin|mingw/) != nil && ents.include?("\x82\xA0".force_encoding("ASCII-8BIT")))
EOS
}
def test_filename_utf8_raw_jp_name
create_and_check_raw_file_name(0x3042, "UTF-8")
end
def test_filename_utf8_raw_windows_1251_name
create_and_check_raw_file_name(0x0424, "UTF-8")
end
def test_filename_utf8_raw_windows_1252_name
create_and_check_raw_file_name(0x00c7, "UTF-8")
end
def test_filename_ext_euc_jp_and_int_utf_8
......
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts)
exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2".force_encoding("euc-jp")))
exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2".force_encoding("euc-jp")))
EOS
assert_ruby_status(%w[-EEUC-JP:UTF-8], <<-'EOS', nil, :chdir=>d)
filename = "\u3042"
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts)
exit ents.include?(filename) || ((RUBY_PLATFORM =~ /darwin/) != nil && ents.include?("%A4%A2"))
exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2"))
EOS
}
end
    (1-1/1)