Bug #21517
closedBehaviour of StringIO#readpartial with multibyte differs from IO#readpartial
Description
The specs for IO#readpartial
have the following test (https://github.com/ruby/spec/blob/ed254bae321221f5cd24280beb37e5bddaff6bb6/core/io/readpartial_spec.rb#L41-L47):
before :each do
@rd, @wr = IO.pipe
@rd.binmode
@wr.binmode
end
it "reads after ungetc with multibyte characters in the buffer" do
@wr.write("∂φ/∂x = gaîté")
c = @rd.getc
@rd.ungetc(c)
@rd.readpartial(3).should == "\xE2\x88\x82"
@rd.readpartial(3).should == "\xCF\x86/"
end
This behaviour is different in StringIO#readpartial
. If I add this as a spec:
it "reads after ungetc with multibyte characters in the buffer" do
@string = StringIO.new(+"∂φ/∂x = gaîté")
c = @string.getc
@string.ungetc(c)
@string.readpartial(3).should == "\xE2\x88\x82"
@string.readpartial(3).should == "\xCF\x86/"
end
it fails with every supported Ruby version, and even with 3.5-dev of today, with the message Expected "\xE2\x88\x82" == "∂"
The getc
+ ungetc
can be removed, but this does not change the behaviour.
Updated by herwin (Herwin W) 10 days ago
Never mind, this was a mistake on my end. The file spec/core/io/readpartial_spec.rb
has a # encoding: binary
directive, once I added that to spec/library/stringio/readpartial_spec.rb
too, the issue was fixed.
Please close this issue, I'll add it to the specs.
Updated by herwin (Herwin W) 10 days ago
For easy reference: https://github.com/ruby/spec/pull/1279
Updated by jeremyevans0 (Jeremy Evans) 10 days ago
- Status changed from Open to Closed