From f81b6694ed7d004054e0d11e6362769461af8905 Mon Sep 17 00:00:00 2001 From: usa Date: Tue, 1 Dec 2015 08:00:58 +0000 Subject: merge revision(s) 51583,51594,51638: [Backport #11444] * io.c (rb_io_each_codepoint): read more data when read partially. [ruby-core:70379] [Bug #11444] * io.c (rb_io_each_codepoint): raise an exception at incomplete character before EOF when conversion takes place. [Bug #11444] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@52831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io_m17n.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'test') diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index 0b435dd8c1..5fbf056cd9 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -1,6 +1,7 @@ # coding: US-ASCII require 'test/unit' require 'tmpdir' +require 'tempfile' require 'timeout' require_relative 'envutil' @@ -2535,4 +2536,42 @@ EOT end } end if /mswin|mingw/ =~ RUBY_PLATFORM + + def test_each_codepoint_need_more + bug11444 = '[ruby-core:70379] [Bug #11444]' + 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 -- cgit v1.2.3