diff options
-rw-r--r-- | string.c | 15 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 12 |
2 files changed, 13 insertions, 14 deletions
@@ -7511,18 +7511,17 @@ rb_str_enumerate_lines(int argc, VALUE *argv, VALUE str, int wantarray) subptr = adjusted; continue; } - subend = hit + rslen; + subend = hit += rslen; if (paragraph_mode) { - while (subend < pend) { + while (hit < pend) { int n; - if (rb_enc_ascget(subend, pend, &n, enc) != '\r') + if (rb_enc_ascget(hit, pend, &n, enc) != '\r') n = 0; - if (!rb_enc_is_newline(subend + n, pend, enc)) break; - subend += n; - subend += rb_enc_mbclen(subend, pend, enc); + if (!rb_enc_is_newline(hit + n, pend, enc)) break; + hit += n; + hit += rb_enc_mbclen(hit, pend, enc); } } - hit = subend; if (chomp) { if (rsnewline) { subend = chomp_newline(subptr, subend, enc); @@ -7591,7 +7590,7 @@ rb_str_enumerate_lines(int argc, VALUE *argv, VALUE str, int wantarray) * "o\nworl" * "d" * Example three - * "hello\n\n\n" + * "hello\n\n" * "world" */ diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 4dee245462..d1da27bdb3 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -661,8 +661,8 @@ CODE res=[] S("hello\n\n\nworld").lines(S('')).each {|x| res << x} - assert_equal(S("hello\n\n\n"), res[0]) - assert_equal(S("world"), res[1]) + assert_equal(S("hello\n\n"), res[0]) + assert_equal(S("world"), res[1]) $/ = "!" res=[] @@ -782,8 +782,8 @@ CODE res=[] S("hello\n\n\nworld").each_line(S('')) {|x| res << x} - assert_equal(S("hello\n\n\n"), res[0]) - assert_equal(S("world"), res[1]) + assert_equal(S("hello\n\n"), res[0]) + assert_equal(S("world"), res[1]) $/ = "!" @@ -824,8 +824,8 @@ CODE res = [] S("hello\n\n\nworld").each_line(S(''), chomp: true) {|x| res << x} - assert_equal(S("hello\n\n"), res[0]) - assert_equal(S("world"), res[1]) + assert_equal(S("hello\n"), res[0]) + assert_equal(S("world"), res[1]) res = [] S("hello!world").each_line(S('!'), chomp: true) {|x| res << x} |