Project

General

Profile

Actions

Bug #18769

closed

StringIO#each hangs up on some input with `chomp: true`

Added by andrykonchin (Andrew Konchin) about 2 months ago. Updated 28 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.3
[ruby-core:<unknown>]

Description

The mentioned StringIO method #each (as well as #readlines and #each_line) may hang up when passed a separator and chomp: true:

require 'stringio'

StringIO.new('a||b||c').each("||", chomp: true) { |s| p s }

""
""
""
""
""
""
""

The same way behave other two methods:

StringIO.new('a||b||c').readlines("||", chomp: true)
StringIO.new('a||b||c').each_line("||", chomp: true) { |s| p s }
Actions #2

Updated by jeremyevans (Jeremy Evans) 28 days ago

  • Status changed from Open to Closed

Applied in changeset git|1f82269f4e1bf037e3e5504c6071b905f26fec6f.


[ruby/stringio] Fix each with multiple character string and chomp

Previously, this could result in an infinite loop. Always update
the e pointer in this case, setting w when chomping so the chomped
data is not included in the output.

Fixes [Bug #18769]

https://github.com/ruby/stringio/commit/4bf64d5130

Actions

Also available in: Atom PDF