Skip to content

Commit 268ef8f

Browse files
committed
A failing test is a start
1 parent 736a313 commit 268ef8f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

spec/zip_kit/streamer_spec.rb

+22
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,26 @@ def stream_with_just_write.write(bytes)
639639
expect(per_filename["deflated.txt"]).to eq("this is attempt 2")
640640
expect(per_filename["stored.txt"]).to eq("this is attempt 2")
641641
end
642+
643+
it "correctly rolls back if an exception is raised after the local entry has been written in write_file" do
644+
# A Unicode string will not be happy about binary writes
645+
# and will raise an exception. The exception won't be raised when
646+
# starting the writes, but in `#close` of the Writable. If this is not handled correctly,
647+
# the exception we will get raised won't be the original exception (Encoding::CompatibilityError that
648+
# we need to see - to know what went wrong inside the writing block) but a duplicate zip entry exception.
649+
# To cause this, we need something that will raise during `Writable#close` - we will use a Unicode string
650+
# for that purpose. See https://github.com/julik/zip_kit/issues/15
651+
uniсode_str_buf = "Ж"
652+
described_class.open(uniсode_str_buf) do |zip|
653+
4.times do
654+
begin
655+
zip.write_file("deflated.txt") do |sink|
656+
sink.write("x")
657+
end
658+
rescue => e
659+
expect(e).to be_kind_of(Encoding::CompatibilityError)
660+
end
661+
end
662+
end
663+
end
642664
end

0 commit comments

Comments
 (0)