ruby-changes:40707
From: nagachika <ko1@a...>
Date: Sun, 29 Nov 2015 17:21:44 +0900 (JST)
Subject: [ruby-changes:40707] nagachika:r52786 (ruby_2_2): merge revision(s) 51583, 51638: [Backport #11444]
nagachika 2015-11-29 17:21:32 +0900 (Sun, 29 Nov 2015) New Revision: 52786 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52786 Log: merge revision(s) 51583,51638: [Backport #11444] * io.c (rb_io_each_codepoint): read more data when read partially. [ruby-core:70379] [Bug #11444] Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog 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 52785) +++ ruby_2_2/ChangeLog (revision 52786) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Sun Nov 29 17:13:16 2015 Nobuyoshi Nakada <nobu@r...> + + * io.c (rb_io_each_codepoint): read more data when read partially. + [ruby-core:70379] [Bug #11444] + Sun Nov 29 16:46:25 2015 SHIBATA Hiroshi <hsbt@r...> * lib/net/http.rb: set hostname before call ossl_ssl_set_session. Index: ruby_2_2/io.c =================================================================== --- ruby_2_2/io.c (revision 52785) +++ ruby_2_2/io.c (revision 52786) @@ -3708,6 +3708,7 @@ rb_io_each_codepoint(VALUE io) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/io.c#L3708 READ_CHECK(fptr); if (NEED_READCONV(fptr)) { SET_BINARY_MODE(fptr); + r = 1; /* no invalid char yet */ for (;;) { make_readconv(fptr, 0); for (;;) { @@ -3762,8 +3763,25 @@ rb_io_each_codepoint(VALUE io) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/io.c#L3763 rb_yield(UINT2NUM(c)); } else if (MBCLEN_INVALID_P(r)) { + invalid: rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(enc)); } + else if (MBCLEN_NEEDMORE_P(r)) { + char cbuf[8], *p = cbuf; + int more = MBCLEN_NEEDMORE_LEN(r); + if (more > numberof(cbuf)) goto invalid; + more += n = fptr->rbuf.len; + if (more > numberof(cbuf)) goto invalid; + while ((n = (int)read_buffered_data(p, more, fptr)) > 0 && + (p += n, (more -= n) > 0)) { + if (io_fillbuf(fptr) < 0) goto invalid; + if ((n = fptr->rbuf.len) > more) n = more; + } + r = rb_enc_precise_mbclen(cbuf, p, enc); + if (!MBCLEN_CHARFOUND_P(r)) goto invalid; + c = rb_enc_codepoint(cbuf, p, enc); + rb_yield(UINT2NUM(c)); + } else { continue; } Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 52785) +++ ruby_2_2/version.h (revision 52786) @@ -1,6 +1,6 @@ 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 211 +#define RUBY_PATCHLEVEL 212 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 11 Index: ruby_2_2/test/ruby/test_io_m17n.rb =================================================================== --- ruby_2_2/test/ruby/test_io_m17n.rb (revision 52785) +++ ruby_2_2/test/ruby/test_io_m17n.rb (revision 52786) @@ -2563,4 +2563,24 @@ EOT https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_io_m17n.rb#L2563 a.close rescue nil b.close rescue nil 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) + end end Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r51583,51638 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/