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

ruby-changes:60215

From: Jeremy <ko1@a...>
Date: Fri, 28 Feb 2020 03:18:16 +0900 (JST)
Subject: [ruby-changes:60215] 54499d7810 (master): Remove support for passing nil to IO#ungetc

https://git.ruby-lang.org/ruby.git/commit/?id=54499d7810

From 54499d78109037d7c37bc09a8c3ffa0050da5aca Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Sun, 25 Aug 2019 11:25:41 -0700
Subject: Remove support for passing nil to IO#ungetc

Fixes [Bug #13675]

diff --git a/io.c b/io.c
index 03209f7..9634e2c 100644
--- a/io.c
+++ b/io.c
@@ -4350,7 +4350,6 @@ rb_io_ungetc(VALUE io, VALUE c) https://github.com/ruby/ruby/blob/trunk/io.c#L4350
 
     GetOpenFile(io, fptr);
     rb_io_check_char_readable(fptr);
-    if (NIL_P(c)) return Qnil;
     if (FIXNUM_P(c)) {
 	c = rb_enc_uint_chr(FIX2UINT(c), io_read_encoding(fptr));
     }
diff --git a/spec/ruby/core/io/ungetc_spec.rb b/spec/ruby/core/io/ungetc_spec.rb
index 34d4caf..4be0e3a 100644
--- a/spec/ruby/core/io/ungetc_spec.rb
+++ b/spec/ruby/core/io/ungetc_spec.rb
@@ -103,10 +103,19 @@ describe "IO#ungetc" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/ungetc_spec.rb#L103
     -> { @io.sysread(1) }.should raise_error(IOError)
   end
 
-  it "does not affect the stream and returns nil when passed nil" do
-    @io.getc.should == ?V
-    @io.ungetc(nil)
-    @io.getc.should == ?o
+  ruby_version_is "0"..."2.8" do
+    it "does not affect the stream and returns nil when passed nil" do
+      @io.getc.should == ?V
+      @io.ungetc(nil)
+      @io.getc.should == ?o
+    end
+  end
+
+  ruby_version_is "2.8" do
+    it "raises TypeError if passed nil" do
+      @io.getc.should == ?V
+      proc{@io.ungetc(nil)}.should raise_error(TypeError)
+    end
   end
 
   it "puts one or more characters back in the stream" do
-- 
cgit v0.10.2


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

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