Skip to content

Commit

Permalink
Fix StringIO#write(str) when str is of an incompatible encoding and p…
Browse files Browse the repository at this point in the history
…osition < buffer size

* Reuse StringIO#write for StringIO#putc to deduplicate logic.
* Retag TestStringIO.
* Fixes oracle/truffleruby#2770
  • Loading branch information
eregon committed Jan 5, 2023
1 parent 33e0545 commit d8ba220
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions library/stringio/shared/write.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@
@io.tainted?.should be_false
end
end

it "handles writing non-ASCII UTF-8 after seek" do
@io.binmode
@io << "\x80"
@io.pos = 0
@io << "\x81"
@io.string.should == "\x812345".b
end

it "handles writing with position < buffer size" do
@io.pos = 2
@io.write "abc"
@io.string.should == "12abc"

@io.pos = 2
@io.write "de"
@io.string.should == "12dec"

@io.pos = 2
@io.write "fghi"
@io.string.should == "12fghi"
end
end

describe :stringio_write_not_writable, shared: true do
Expand Down

0 comments on commit d8ba220

Please sign in to comment.