From: "rhenium (Kazuki Yamaguchi) via ruby-core" Date: 2026-09-22T16:22:12+00:00 Subject: [ruby-core:126829] [Ruby Bug#22342] IO#gets can ignore the limit argument in some edge cases Issue #22342 has been updated by rhenium (Kazuki Yamaguchi). I've opened a GitHub PR for this: https://github.com/ruby/ruby/pull/18961 ---------------------------------------- Bug #22342: IO#gets can ignore the limit argument in some edge cases https://bugs.ruby-lang.org/issues/22342#change-119140 * Author: rhenium (Kazuki Yamaguchi) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: REQUIRED, 4.0: REQUIRED ---------------------------------------- `io.gets(rs, limit)` ignores the `limit` value and reads until `rs` is found or EOF, if the `limit`-th byte of the stream matches `rs`'s last byte and: 1. The potential start of the record separator, the `limit-rs.bytesize`-th byte of the stream is not at a character boundary ```ruby str = "\x83\\xxx".force_encoding("Windows-31J") # "���xxx".encode("Windows-31J") IO.pipe("Windows-31J"){|r,w|w.write(str); w.close_write; p r.gets("\\", 2); p r.read} # Expected: "\x{835C}" "xxx" # Actual: "\x{835C}xxx" "" ``` 2. Or, `limit < rs.bytesize` ```ruby IO.pipe{|r,w|w.write("a:bc"); w.close_write; p r.gets(":::", 2); p r.read} # Expected: "a:" "bc" # Actual: "a:bc" "" ``` This behavior appears to date back to Ruby 1.9.x. -- 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/lists/ruby-core.ml.ruby-lang.org/