Project

General

Profile

Actions

Bug #22342

open

IO#gets can ignore the limit argument in some edge cases

Bug #22342: IO#gets can ignore the limit argument in some edge cases

Added by rhenium (Kazuki Yamaguchi) about 16 hours ago. Updated about 16 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:126828]

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:

  1. 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"
""
  1. 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.

Actions

Also available in: PDF Atom