ruby-changes:54981
From: nobu <ko1@a...>
Date: Thu, 7 Mar 2019 14:11:51 +0900 (JST)
Subject: [ruby-changes:54981] nobu:r67188 (trunk): io.c: chomp CR at the end of read buffer
nobu 2019-03-07 14:11:46 +0900 (Thu, 07 Mar 2019) New Revision: 67188 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67188 Log: io.c: chomp CR at the end of read buffer * io.c (rb_io_getline_fast): chomp CR followed by LF but separated by the read buffer boundary. [ruby-core:91707] [Bug #15642] Modified files: trunk/io.c trunk/test/ruby/test_io.rb Index: io.c =================================================================== --- io.c (revision 67187) +++ io.c (revision 67188) @@ -3310,6 +3310,12 @@ rb_io_getline_fast(rb_io_t *fptr, rb_enc https://github.com/ruby/ruby/blob/trunk/io.c#L3310 read_buffered_data(RSTRING_PTR(str)+len, pending - chomplen, fptr); fptr->rbuf.off += chomplen; fptr->rbuf.len -= chomplen; + if (pending == 1 && chomplen == 1 && len > 0) { + if (RSTRING_PTR(str)[len-1] == '\r') { + rb_str_resize(str, --len); + break; + } + } } len += pending - chomplen; if (cr != ENC_CODERANGE_BROKEN) Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 67187) +++ test/ruby/test_io.rb (revision 67188) @@ -233,6 +233,19 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L233 assert_nil r.gets r.close end) + + (0..3).each do |i| + pipe(proc do |w| + w.write("a" * ((4096 << i) - 4), "\r\n" "a\r\n") + w.close + end, + proc do |r| + r.gets + assert_equal "a", r.gets(chomp: true) + assert_nil r.gets + r.close + end) + end end def test_gets_chomp_rs_nil -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/