diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-24 03:07:49 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-24 03:07:49 +0000 |
commit | 3cc5ddcac142317709aa235a27d8ce0a84140150 (patch) | |
tree | 1e3bc3cf086c47d524182fe7febc253f0e66a7e8 /test | |
parent | c427f44f1092c96a3bd3ea90d10ec591f3a93f94 (diff) | |
download | ruby-3cc5ddcac142317709aa235a27d8ce0a84140150.tar.gz |
Bug #6487
* io.c (io_strip_bom): check EOF. [Bug #6487][ruby-core:45203]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_file.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index 54983d6deb..f94e4336d7 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -38,6 +38,57 @@ class TestFile < Test::Unit::TestCase include TestEOF::Seek + def test_empty_file_bom + bug6487 = '[ruby-core:45203]' + f = Tempfile.new(__method__.to_s) + f.close + assert File.exist? f.path + assert_nothing_raised(bug6487) {File.read(f.path, mode: 'r:utf-8')} + assert_nothing_raised(bug6487) {File.read(f.path, mode: 'r:bom|utf-8')} + f.close(true) + end + + def assert_bom(bytes, name) + bug6487 = '[ruby-core:45203]' + + f = Tempfile.new(name.to_s) + f.sync = true + expected = "" + result = nil + bytes[0...-1].each do |x| + f.write x + f.write ' ' + f.pos -= 1 + expected << x + assert_nothing_raised(bug6487) {result = File.read(f.path, mode: 'rb:bom|utf-8')} + assert_equal("#{expected} ".force_encoding("utf-8"), result) + end + f.write bytes[-1] + assert_nothing_raised(bug6487) {result = File.read(f.path, mode: 'rb:bom|utf-8')} + assert_equal '', result, "valid bom" + f.close(true) + end + + def test_bom_8 + assert_bom(["\xEF", "\xBB", "\xBF"], __method__) + end + + def test_bom_16be + assert_bom(["\xFE", "\xFF"], __method__) + end + + def test_bom_16le + assert_bom(["\xFF", "\xFE"], __method__) + end + + def test_bom_32be + assert_bom(["\0", "\0", "\xFE", "\xFF"], __method__) + end + + def test_bom_32le + assert_bom(["\xFF\xFE\0", "\0"], __method__) + end + def test_truncate_wbuf f = Tempfile.new("test-truncate") f.print "abc" |