Skip to content

Commit

Permalink
Fix StringIO#initialize and preserve initial string's encoding when m…
Browse files Browse the repository at this point in the history
…ode is `w` so the initial string is truncated

* close oracle/truffleruby#3599
  • Loading branch information
andrykonchin committed Jul 1, 2024
1 parent b4faebd commit 612518f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions library/stringio/initialize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@
-> { @io.send(:initialize, str, "w") }.should raise_error(Errno::EACCES)
-> { @io.send(:initialize, str, "a") }.should raise_error(Errno::EACCES)
end

it "truncates all the content if passed w mode" do
io = StringIO.allocate
source = +"example".encode(Encoding::ISO_8859_1);

io.send(:initialize, source, "w")

io.string.should.empty?
io.string.encoding.should == Encoding::ISO_8859_1
end

it "truncates all the content if passed IO::TRUNC mode" do
io = StringIO.allocate
source = +"example".encode(Encoding::ISO_8859_1);

io.send(:initialize, source, IO::TRUNC)

io.string.should.empty?
io.string.encoding.should == Encoding::ISO_8859_1
end
end

describe "StringIO#initialize when passed [Object]" do
Expand Down

0 comments on commit 612518f

Please sign in to comment.