ruby-changes:48768
From: nobu <ko1@a...>
Date: Thu, 23 Nov 2017 16:11:02 +0900 (JST)
Subject: [ruby-changes:48768] nobu:r60884 (trunk): io.c: read BOM only for reading
nobu 2017-11-23 16:10:56 +0900 (Thu, 23 Nov 2017) New Revision: 60884 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60884 Log: io.c: read BOM only for reading * io.c (io_strip_bom): just abandon detecting UTF encoding by BOM unless opened for reading. Modified files: trunk/io.c trunk/test/ruby/test_io_m17n.rb Index: io.c =================================================================== --- io.c (revision 60883) +++ io.c (revision 60884) @@ -5970,7 +5970,10 @@ static int https://github.com/ruby/ruby/blob/trunk/io.c#L5970 io_strip_bom(VALUE io) { VALUE b1, b2, b3, b4; + rb_io_t *fptr; + GetOpenFile(io, fptr); + if (!(fptr->mode & FMODE_READABLE)) return 0; if (NIL_P(b1 = rb_io_getbyte(io))) return 0; switch (b1) { case INT2FIX(0xEF): Index: test/ruby/test_io_m17n.rb =================================================================== --- test/ruby/test_io_m17n.rb (revision 60883) +++ test/ruby/test_io_m17n.rb (revision 60884) @@ -2168,6 +2168,20 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L2168 assert_nil(enc) end + def test_bom_non_reading + with_tmpdir { + enc = nil + assert_nothing_raised(IOError) { + open("test", "w:bom|utf-8") {|f| + enc = f.external_encoding + f.print("abc") + } + } + assert_equal(Encoding::UTF_8, enc) + assert_equal("abc", File.binread("test")) + } + end + def test_cbuf with_tmpdir { fn = "tst" -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/