From d27ee2112ff81d4d445a2a9bd6df538aca16f1fd Mon Sep 17 00:00:00 2001 From: naruse Date: Mon, 11 Mar 2019 06:45:29 +0000 Subject: 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 --- io.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'io.c') diff --git a/io.c b/io.c index 7de405de32..07c678f855 100644 --- a/io.c +++ b/io.c @@ -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) -- cgit v1.2.3