You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ARGF.getc and ARGF.readchar return byte Integers instead of one-character Strings #10032
JRuby 10.1.2.0 and the nightly 10.1.4.0-SNAPSHOT (5daf993, 2026-11-07) print the same. With input from stdin (ruby repro.rb < input.txt) JRuby prints the same as CRuby, and File#getc on the same file returns "h".
When the current file is a RubyFile, RubyArgsFile#getc calls getbyte on it; only other kinds of input (stdin, for example) go through getc (RubyArgsFile.java#L891-L895). readchar is built on that getc (#L793-L800). This looks like Ruby 1.8 behavior that was kept: up to 9.2 the call was RubyIO#getc(), a deprecated method that returned getbyte, and c10d686 replaced it with getbyte(context) directly. CRuby's argf_getc and argf_readchar call rb_io_getc on a file (io.c#L14121-L14140). Calling RubyIO#getc(context) there should match it. each_byte and each_char in the same file call this getc too, so they would need to switch to getbyte if getc changes.
ruby/spec's core/argf/shared/getc.rb builds the result with chars << @argf.send(@method) from ASCII fixtures and compares it with the file contents, and an Integer passes that (getc.rb#L10-L16). CRuby's test_getc and test_readchar in test/ruby/test_argf.rb do the same with s << c, so neither catches this.
Found while comparing JRuby with CRuby on ruby/spec-based checks.
Activity