[前][次][番号順一覧][スレッド一覧]

ruby-changes:72629

From: Jeremy <ko1@a...>
Date: Fri, 22 Jul 2022 00:30:42 +0900 (JST)
Subject: [ruby-changes:72629] 203f179ce7 (master): Revert "Do not chomp trailing line separator IO#each with nil separator and chomp"

https://git.ruby-lang.org/ruby.git/commit/?id=203f179ce7

From 203f179ce7d1bde0befb8d12148aa392ad45ac56 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Thu, 21 Jul 2022 08:29:50 -0700
Subject: Revert "Do not chomp trailing line separator IO#each with nil
 separator and chomp"

This reverts commit 04f86ad0b5d2fe4711ff300d855228a6aed55f33.

This is causing CI issues, reverting for now.
---
 io.c                 |  1 +
 test/ruby/test_io.rb | 16 +---------------
 2 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/io.c b/io.c
index 13cde15360..650ea5e377 100644
--- a/io.c
+++ b/io.c
@@ -3875,6 +3875,7 @@ rb_io_getline_0(VALUE rs, long limit, int chomp, rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/io.c#L3875
     if (NIL_P(rs) && limit < 0) {
 	str = read_all(fptr, 0, Qnil);
 	if (RSTRING_LEN(str) == 0) return Qnil;
+	if (chomp) rb_str_chomp_string(str, rb_default_rs);
     }
     else if (limit == 0) {
 	return rb_enc_str_new(0, 0, io_read_encoding(fptr));
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index b8530e7400..0f42d8e164 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -312,7 +312,7 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L312
       w.print "a\n\nb\n\n"
       w.close
     end, proc do |r|
-      assert_equal("a\n\nb\n\n", r.gets(nil, chomp: true), "[Bug #18770]")
+      assert_equal "a\n\nb\n", r.gets(nil, chomp: true)
       assert_nil r.gets("")
       r.close
     end)
@@ -1894,20 +1894,6 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L1894
       assert_equal("baz\n", e.next)
       assert_raise(StopIteration) { e.next }
     end)
-
-    pipe(proc do |w|
-      w.write "foo\n"
-      w.close
-    end, proc do |r|
-      assert_equal(["foo\n"], r.each_line(nil, chomp: true).to_a, "[Bug #18770]")
-    end)
-
-    pipe(proc do |w|
-      w.write "foo\n"
-      w.close
-    end, proc do |r|
-      assert_equal(["fo", "o\n"], r.each_line(nil, 2, chomp: true).to_a, "[Bug #18770]")
-    end)
   end
 
   def test_each_byte2
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]