Actions
Bug #22342
openIO#gets can ignore the limit argument in some edge cases
Bug #22342:
IO#gets can ignore the limit argument in some edge cases
Description
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:
- The potential start of the record separator, the
limit-rs.bytesize-th byte of the stream is not at a character boundary
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"
""
- Or,
limit < rs.bytesize
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.
Updated by rhenium (Kazuki Yamaguchi) about 16 hours ago
I've opened a GitHub PR for this: https://github.com/ruby/ruby/pull/18961
Actions