From: "naruse (Yui NARUSE) via ruby-core" Date: 2023-01-31T04:38:58+00:00 Subject: [ruby-core:112129] [Ruby master Bug#19389] StringIO gets(..., chomp: true) behaves differently to File/IO. Issue #19389 has been updated by naruse (Yui NARUSE). 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. ---------------------------------------- Bug #19389: StringIO gets(..., chomp: true) behaves differently to File/IO. https://bugs.ruby-lang.org/issues/19389#change-101565 * Author: ioquatix (Samuel Williams) * Status: Closed * Priority: Normal * Backport: 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED, 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") => # 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 => # 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/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/