Project

General

Profile

Actions

Bug #19389

closed

StringIO gets(..., chomp: true) behaves differently to File/IO.

Added by ioquatix (Samuel Williams) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:112098]

Description

It seems like StringIO and File #gets(..., chomp: true) have different behaviour.

irb(main):003:0> io = StringIO.new("foo\r\nbar\r\n\r\n")
=> #<StringIO:0x00000001077e2018>
irb(main):004:0> io.gets("\r\n", chomp: true)
=> "foo"
irb(main):005:0> io.gets("\r\n", chomp: true)
=> "bar"
irb(main):006:0> io.gets("\r\n", chomp: true)
=> "\r\n"

compared with File:

irb(main):008:0> io = Tempfile.new
=> #<File:/var/folders/cm/p8lkj40s0vz_vgx_b5df9dkm0000gn/T/20230128-37714-107ims>
irb(main):009:0> io.write("foo\r\nbar\r\n\r\n")
=> 12
irb(main):012:0> io.rewind
=> 0
irb(main):013:0> io.gets("\r\n", chomp: true)
=> "foo"
irb(main):014:0> io.gets("\r\n", chomp: true)
=> "bar"
irb(main):015:0> io.gets("\r\n", chomp: true)
=> ""
Actions #1

Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

  • Status changed from Open to Closed

Applied in changeset git|21dced8b01823a991829b66ffdc8ffc635965c76.


[ruby/stringio] [Bug #19389] Fix chomping with longer separator

https://github.com/ruby/stringio/commit/eb322a9716

Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 2 years ago

  • Backport changed from 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED

Updated by naruse (Yui NARUSE) almost 2 years ago

  • Backport changed from 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONE

ruby_3_2 1689d8bb4843f92c1805e4a4bdd94049569198f4 merged revision(s) 21dced8b01823a991829b66ffdc8ffc635965c76.

Updated by ioquatix (Samuel Williams) almost 2 years ago

Team, thanks for your hard work dealing with this bug.

Updated by nagachika (Tomoyuki Chikanaga) almost 2 years ago

  • Backport changed from 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONE to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE, 3.2: DONE

ruby_3_1 1d24a931c458c93463da1d5885f33edef3677cc2 merged revision(s) 21dced8b01823a991829b66ffdc8ffc635965c76.

Updated by ioquatix (Samuel Williams) almost 2 years ago

Thanks for your hard work back porting this.

Actions

Also available in: Atom PDF

Like0
Like1Like0Like0Like0Like0Like0