Project

General

Profile

Actions

Backport #5207

closed

StringIO#read(length,nil) does not behave in the same way as IO#read

Added by postmodern (Hal Brodigan) over 12 years ago. Updated almost 8 years ago.

Status:
Rejected
[ruby-core:39026]

Description

I noticed an incompatibility between IO#read(length,buffer) and StringIO#read, when buffer is nil.

file = File.read('test')
file.read(2,nil)
# => "12"

string = StringIO.new("hello")
string.read(2,nil)
TypeError: can't convert nil into String
from (irb):3:in `read'
from (irb):3
from /home/hal/.rvm/rubies/ruby-1.9.3-preview1/bin/irb:16:in `<main>'

Effects both 1.9.2-p290 and 1.9.3-preview1.

Updated by postmodern (Hal Brodigan) over 12 years ago

Oops, that should be:

file = File.new('test')
file.read(2,nil)
# => "12"

require 'stringio'
stringio = StringIO.new("hello")
stringio.read(2,nil)
TypeError: can't convert nil into String
  from (irb):3:in `read'
  from (irb):3 from /home/hal/.rvm/rubies/ruby-1.9.3-preview1/bin/irb:16:in `<main>' 
Actions #2

Updated by nobu (Nobuyoshi Nakada) over 12 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r33010.
Hal, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • ext/stringio/stringio.c (strio_read): return new string if nil
    is explicitly given as a buffer ([Bug #5207]), otherwise set the
    encoding. also removed dead code.
Actions #3

Updated by nobu (Nobuyoshi Nakada) over 12 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport192
  • Category changed from lib to lib
  • Status changed from Closed to Assigned
  • Assignee set to yugui (Yuki Sonoda)
  • Target version deleted (1.9.3)
Actions #4

Updated by naruse (Yui NARUSE) almost 8 years ago

  • Status changed from Assigned to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0