summaryrefslogtreecommitdiff
path: root/test/ruby/test_io_m17n.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-25 07:11:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-25 07:11:20 +0000
commit91fb5bc88992dd7f4edae20934f814f052b516d6 (patch)
tree399441d230a2ade72965e299b88f61c54a02d67f /test/ruby/test_io_m17n.rb
parent8b29525dadeaba1ba6dc2a9ea5e590aa9d1d825a (diff)
io.c: conversion from bom encoding
* io.c (rb_io_ext_int_to_encs, parse_mode_enc): bom-prefixed name is not a real encoding name, just a fallback. so the proper conversion should take place even if if the internal encoding is equal to the bom-prefixed name, unless actual encoding is equal to the internal encoding. [ruby-core:54563] [Bug #8323] * io.c (io_set_encoding_by_bom): reset extenal encoding if no BOM found. [ruby-core:54569] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_io_m17n.rb')
-rw-r--r--test/ruby/test_io_m17n.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 45ae75c6aa6..ec2086186cc 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -1997,6 +1997,7 @@ EOT
def test_strip_bom
with_tmpdir {
text = "\uFEFFa"
+ stripped = "a"
%w/UTF-8 UTF-16BE UTF-16LE UTF-32BE UTF-32LE/.each do |name|
path = '%s-bom.txt' % name
content = text.encode(name)
@@ -2004,11 +2005,32 @@ EOT
result = File.read(path, mode: 'rb:BOM|UTF-8')
assert_equal(content[1].force_encoding("ascii-8bit"),
result.force_encoding("ascii-8bit"))
+ result = File.read(path, mode: 'rb:BOM|UTF-8:UTF-8')
+ assert_equal(Encoding::UTF_8, result.encoding)
+ assert_equal(stripped, result)
end
bug3407 = '[ruby-core:30641]'
- result = File.read('UTF-8-bom.txt', encoding: 'BOM|UTF-8')
+ path = 'UTF-8-bom.txt'
+ result = File.read(path, encoding: 'BOM|UTF-8')
assert_equal("a", result.force_encoding("ascii-8bit"), bug3407)
+
+ bug8323 = '[ruby-core:54563] [Bug #8323]'
+ expected = "a\xff".force_encoding("utf-8")
+ open(path, 'ab') {|f| f.write("\xff")}
+ result = File.read(path, encoding: 'BOM|UTF-8')
+ assert_not_predicate(result, :valid_encoding?, bug8323)
+ assert_equal(expected, result, bug8323)
+ result = File.read(path, encoding: 'BOM|UTF-8:UTF-8')
+ assert_not_predicate(result, :valid_encoding?, bug8323)
+ assert_equal(expected, result, bug8323)
+
+ path = 'ascii.txt'
+ generate_file(path, stripped)
+ result = File.read(path, encoding: 'BOM|UTF-8')
+ assert_equal(stripped, result, bug8323)
+ result = File.read(path, encoding: 'BOM|UTF-8:UTF-8')
+ assert_equal(stripped, result, bug8323)
}
end