
Issue #19389 has been updated by nagachika (Tomoyuki Chikanaga). 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. ---------------------------------------- Bug #19389: StringIO gets(..., chomp: true) behaves differently to File/IO. https://bugs.ruby-lang.org/issues/19389#change-102486 * Author: ioquatix (Samuel Williams) * Status: Closed * Priority: Normal * Backport: 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE, 3.2: DONE ---------------------------------------- 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) => "" ``` -- https://bugs.ruby-lang.org/