ruby-changes:40725
From: nagachika <ko1@a...>
Date: Tue, 1 Dec 2015 02:36:17 +0900 (JST)
Subject: [ruby-changes:40725] nagachika:r52804 (ruby_2_2): merge revision(s) 51594: [Backport #11444]
nagachika 2015-12-01 02:35:56 +0900 (Tue, 01 Dec 2015) New Revision: 52804 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52804 Log: merge revision(s) 51594: [Backport #11444] * io.c (rb_io_each_codepoint): raise an exception at incomplete character before EOF when conversion takes place. [Bug #11444] Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/NEWS branches/ruby_2_2/io.c branches/ruby_2_2/test/ruby/test_io_m17n.rb branches/ruby_2_2/version.h Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 52803) +++ ruby_2_2/ChangeLog (revision 52804) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Tue Dec 1 02:27:41 2015 Nobuyoshi Nakada <nobu@r...> + + * io.c (rb_io_each_codepoint): raise an exception at incomplete + character before EOF when conversion takes place. [Bug #11444] + Sun Nov 29 18:02:44 2015 Shugo Maeda <shugo@r...> * io.c (argf_getpartial): should not resize str if the second Index: ruby_2_2/io.c =================================================================== --- ruby_2_2/io.c (revision 52803) +++ ruby_2_2/io.c (revision 52804) @@ -3727,13 +3727,16 @@ rb_io_each_codepoint(VALUE io) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/io.c#L3727 } if (more_char(fptr) == MORE_CHAR_FINISHED) { clear_readconv(fptr); - /* ignore an incomplete character before EOF */ + if (!MBCLEN_CHARFOUND_P(r)) { + enc = fptr->encs.enc; + goto invalid; + } return io; } } if (MBCLEN_INVALID_P(r)) { - rb_raise(rb_eArgError, "invalid byte sequence in %s", - rb_enc_name(fptr->encs.enc)); + enc = fptr->encs.enc; + goto invalid; } n = MBCLEN_CHARFOUND_LEN(r); if (fptr->encs.enc) { Index: ruby_2_2/NEWS =================================================================== --- ruby_2_2/NEWS (revision 52803) +++ ruby_2_2/NEWS (revision 52804) @@ -111,6 +111,8 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/ruby_2_2/NEWS#L111 of the file is updated immediately. On some platforms (especially Windows), it is delayed until the filesystem load is decreased. Use IO#fsync if you want to guarantee updating metadata. + * IO#each_codepoint raises an exception at incomplete character + before EOF when conversion takes place. [Bug #11444] * Math * incompatible changes: Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 52803) +++ ruby_2_2/version.h (revision 52804) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.4" -#define RUBY_RELEASE_DATE "2015-11-29" -#define RUBY_PATCHLEVEL 214 +#define RUBY_RELEASE_DATE "2015-12-01" +#define RUBY_PATCHLEVEL 215 #define RUBY_RELEASE_YEAR 2015 -#define RUBY_RELEASE_MONTH 11 -#define RUBY_RELEASE_DAY 29 +#define RUBY_RELEASE_MONTH 12 +#define RUBY_RELEASE_DAY 1 #include "ruby/version.h" Index: ruby_2_2/test/ruby/test_io_m17n.rb =================================================================== --- ruby_2_2/test/ruby/test_io_m17n.rb (revision 52803) +++ ruby_2_2/test/ruby/test_io_m17n.rb (revision 52804) @@ -1,6 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_io_m17n.rb#L1 # coding: US-ASCII require 'test/unit' require 'tmpdir' +require 'tempfile' require 'timeout' class TestIO_M17N < Test::Unit::TestCase @@ -2565,22 +2566,40 @@ EOT https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_io_m17n.rb#L2566 end def test_each_codepoint_need_more - code = <<-'end;' - c = nil - begin - STDIN.set_encoding(Encoding::UTF_8).each_codepoint{|i| c = i} - rescue ArgumentError => e - STDERR.puts e.message - else - printf "%x", c - end - end; - args = ['-e', code] bug11444 = '[ruby-core:70379] [Bug #11444]' - assert_in_out_err(args, "\u{1f376}".b[0,3], [], - ["invalid byte sequence in UTF-8"], - bug11444, timeout: 1) - assert_in_out_err(args, "x"*8190+"\u{1f376}", ["1f376"], [], - bug11444, timeout: 1) + tests = [ + ["incomplete multibyte", "\u{1f376}".b[0,3], [], ["invalid byte sequence in UTF-8"]], + ["multibyte at boundary", "x"*8190+"\u{1f376}", ["1f376"], []], + ] + failure = [] + ["bin", "text"].product(tests) do |mode, (test, data, out, err)| + code = <<-"end;" + c = nil + begin + open(ARGV[0], "r#{mode[0]}:utf-8") do |f| + f.each_codepoint{|i| c = i} + end + rescue ArgumentError => e + STDERR.puts e.message + else + printf "%x", c + end + end; + Tempfile.create("codepoint") do |f| + args = ['-e', code, f.path] + f.print data + f.close + begin + assert_in_out_err(args, "", out, err, + "#{bug11444}: #{test} in #{mode} mode", + timeout: 1) + rescue Exception => e + failure << e + end + end + end + unless failure.empty? + flunk failure.join("\n---\n") + end end end Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r51594 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/