Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Avoid IO operations that are affected by the presence or absence of an encoding converter

Aperta
#1,387 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
ruby
Ambito
testing

Direzione di ricerca

Inizia dagli esempi che falliscono in spec/ruby/core/io/getbyte_spec.rb, read_spec.rb, readbyte_spec.rb e ungetc_spec.rb, quindi eseguili con CRuby e JRuby. Confronta i fallimenti relativi a IO#ungetc, alle letture orientate ai byte e alla conversione della codifica per determinare quali aspettative siano portabili. Il lavoro è completato quando le spec interessate hanno un risultato giustificato e coerente nelle configurazioni indicate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I think that mixing IO#ungetc with certain operations is not a recommended practice, as it may cause issues depending on the platform or input.
Perhaps it would be better to exclude this from testing as well.
I would like to hear your thoughts.

Background

When I'm working on a patched version of CRuby that uses an encoding converter when opening files with the “r” option, I found the following error occurred on CI.
My working branch is at https://github.com/YO4/ruby/tree/newline_fastpath.
I'm aiming to merge this patch, but I'm not sure if I should just skip the spec.

 1)
  IO#getbyte reads after ungetc without character conversion ERROR
  IOError: byte oriented read for character buffered IO
  D:/a/ruby/ruby/src/spec/ruby/core/io/getbyte_spec.rb:33:in 'IO#getbyte'
  D:/a/ruby/ruby/src/spec/ruby/core/io/getbyte_spec.rb:33:in 'block (2 levels) in <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/io/getbyte_spec.rb:5:in '<top (required)>'
  
  2)
  IO#read with internal encoding not specified reads after ungetc ERROR
  IOError: byte oriented read for character buffered IO
  D:/a/ruby/ruby/src/spec/ruby/core/io/read_spec.rb:694:in 'IO#read'
  D:/a/ruby/ruby/src/spec/ruby/core/io/read_spec.rb:694:in 'block (4 levels) in <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/io/read_spec.rb:655:in '<top (required)>'
  
  3)
  IO#readbyte reads after ungetc without character conversion ERROR
  IOError: byte oriented read for character buffered IO
  D:/a/ruby/ruby/src/spec/ruby/core/io/readbyte_spec.rb:29:in 'IO#readbyte'
  D:/a/ruby/ruby/src/spec/ruby/core/io/readbyte_spec.rb:29:in 'block (2 levels) in <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/io/readbyte_spec.rb:3:in '<top (required)>'
  
  4)
  IO#ungetc adjusts the stream position FAILED
  Expected 1 == 0
  to be truthy but was false
  D:/a/ruby/ruby/src/spec/ruby/core/io/ungetc_spec.rb:91:in 'block (2 levels) in <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/io/ungetc_spec.rb:5:in '<top (required)>'

Also, JRuby already uses an encoding converter for crlf conversion in open(name, “r”).

C:\jruby-10.1.1.0\bin>jruby D:/git/ruby/spec/mspec/bin/mspec-run d:/git/ruby/spec/ruby/core/io/getbyte_spec.rb
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by com.kenai.jffi.internal.StubLoader in an unnamed module
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled

jruby 10.1.1.0 (4.0.0) 2026-07-22 aaa95d57e1 OpenJDK 64-Bit Server VM 25.0.1+8-LTS on 25.0.1+8-LTS +indy +jit [x86_64-mswin32]

1)
IO#getbyte reads after ungetc without character conversion ERROR
IOError: byte oriented read for character buffered IO
org/jruby/RubyIO.java:3175:in 'getbyte'
D:/git/ruby/spec/ruby/core/io/getbyte_spec.rb:33:in 'block in <main>'
org/jruby/RubyBasicObject.java:2777:in 'instance_exec'
org/jruby/RubyArrayNative.java:4226:in 'all?'
org/jruby/RubyArrayNative.java:1729:in 'each'
D:/git/ruby/spec/ruby/core/io/getbyte_spec.rb:5:in '<main>'
org/jruby/RubyKernel.java:1413:in 'load'
org/jruby/RubyBasicObject.java:2777:in 'instance_exec'
org/jruby/RubyArrayNative.java:1729:in 'each'
[/ | ==================100%================== | 00:00:00]      0F      1E

Finished in 0.044000 seconds

1 file, 6 examples, 6 expectations, 0 failures, 1 error, 0 tagged

JRuby's CI appears to be green at first glance, but I am unfamiliar with that situation.

Lingua principale
Ruby
Stelle
622
Fork
402
Merge medio
14h 51m
PR unite (30g)
6

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/spec

Tutte le issue di ruby/spec

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.