[ruby-core:62645] [ruby-trunk - Bug #4225] [Rejected] IO.foreach should only accept string arguments

From: nobu@...
Date: 2014-05-17 20:18:03 UTC
List: ruby-core #62645
Issue #4225 has been updated by Nobuyoshi Nakada.

Description updated
Status changed from Open to Rejected

Not only `IO.foreach`, an enumerator defers argument check in general.

----------------------------------------
Bug #4225: IO.foreach should only accept string arguments
https://bugs.ruby-lang.org/issues/4225#change-46780

* Author: Daniel Berger
* Status: Rejected
* Priority: Normal
* Assignee: 
* Category: core
* Target version: 
* ruby -v: ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin8.11.1]
* Backport: 
----------------------------------------
It looks like the `IO.foreach` method doesn't check its argument type first if no block is provided:

~~~ruby
fh = File.new('somefile.txt')

IO.foreach(fh.fileno) # Or, IO.foreach(999999999)
=> #<Enumerable::Enumerator:0x110b0d4>

IO.foreach(fh.fileno){ |line| p line }
TypeError: can't convert Fixnum into String
~~~

I'd flip these two lines in io.c:

~~~C
RETURN_ENUMERATOR(self, argc, argv);
SafeStringValue(fname);
~~~

Otherwise, what am I enumerating?




-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next