Skip to content

StringIO#gets("\r\n", 10) returns an extra \n #3856

@eregon

Description

@eregon
Member

From ruby/net-imap#470 (comment) by @nevans

@eregon here's the issue I saw with IO#gets(CRLF, limit):

#!/usr/bin/env ruby

puts ?=*72
puts "Ruby Engine:   #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION}"

require 'bundler/inline'
gemfile do
  gem "stringio", ">= 3.1.7"
end
require "stringio"
puts "Using StringIO #{StringIO::VERSION}"
io = StringIO.new("123456789\r\n123456789\r\n")
pp stringio: io.gets("\r\n", 10)

r, w = IO.pipe
w.write "123456789\r\n123456789\r\n"
w.close
pp io_pipe: r.gets("\r\n", 10)

__END__
$ ruby test.rb && RBENV_VERSION=truffleruby-24.2.1 ruby test.rb
========================================================================
Ruby Engine:   ruby 3.4.2
Using StringIO 3.1.7
{stringio: "123456789\r"}
{io_pipe: "123456789\r"}
========================================================================
Ruby Engine:   truffleruby 24.2.1
Using StringIO 3.0.1
{:stringio=>"123456789\r\n"}
{:io_pipe=>"123456789\r"}

I didn't make a TruffleRuby ticket for this. I'm guessing this is already a known issue, given that it silently failed to use a newer version of StringIO (even after I manually gem installed it). And it looks like it only affects the test which uses StringIO and probably doesn't affect real IO.

Activity

changed the title [-]StringIO#.gets("\r\n", 10) returns an extra \n[/-] [+]StringIO#gets("\r\n", 10) returns an extra \n[/+] on May 8, 2025
self-assigned this
on May 19, 2025
andrykonchin

andrykonchin commented on May 27, 2025

@andrykonchin
Member

Fixed in 2173a93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @eregon@andrykonchin

      Issue actions

        StringIO#gets("\r\n", 10) returns an extra \n · Issue #3856 · oracle/truffleruby