1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

merge revision(s) 67188: [Backport #15642]

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2019-03-11 06:45:29 +00:00
parent ce5590fc9f
commit d27ee2112f
3 changed files with 21 additions and 2 deletions

6
io.c
View file

@ -3306,6 +3306,12 @@ rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc, int chomp)
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)

View file

@ -233,6 +233,19 @@ class TestIO < Test::Unit::TestCase
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

View file

@ -1,10 +1,10 @@
#define RUBY_VERSION "2.6.1"
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 40
#define RUBY_PATCHLEVEL 41
#define RUBY_RELEASE_YEAR 2019
#define RUBY_RELEASE_MONTH 3
#define RUBY_RELEASE_DAY 6
#define RUBY_RELEASE_DAY 11
#include "ruby/version.h"