Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,13 @@ rb_deflate_init_copy(VALUE self, VALUE orig)
raise_zlib_error(err, 0);
}
z1->input = NIL_P(z2->input) ? Qnil : rb_str_dup(z2->input);
z1->buf = NIL_P(z2->buf) ? Qnil : rb_str_dup(z2->buf);
z1->buf = Qnil;
if (!NIL_P(z2->buf)) {
/* next_out was copied from orig; point it into our own buffer */
z1->buf = rb_obj_hide(rb_str_new(RSTRING_PTR(z2->buf), RSTRING_LEN(z2->buf)));
z1->stream.next_out = (Bytef*)RSTRING_END(z1->buf);
z1->stream.avail_out = 0;
}
z1->flags = z2->flags;

return self;
Expand Down
11 changes: 11 additions & 0 deletions test/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ def test_dup
assert_equal("foobaz", Zlib::Inflate.inflate(s2))
end

def test_dup_with_pending_output
s = Random.new(0).bytes(50_000)
z1 = Zlib::Deflate.new
z1 << s
z2 = z1.dup
z1 << "bar"
z2 << "baz"
assert_equal(s + "bar", Zlib::Inflate.inflate(z1.finish))
assert_equal(s + "baz", Zlib::Inflate.inflate(z2.finish))
end

def test_deflate
s = Zlib::Deflate.deflate("foo")
assert_equal("foo", Zlib::Inflate.inflate(s))
Expand Down
Loading