Skip to content

Commit

Permalink
Fix for JRUBY-4503: recover pass-through behavior of Zlib::Inflate.
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Sizikov <vsizikov@gmail.com>
  • Loading branch information
nahi authored and headius committed Jan 21, 2010
1 parent 63b7f09 commit 34624c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/org/jruby/RubyZlib.java
Expand Up @@ -575,10 +575,6 @@ private IRubyObject set_dictionary(IRubyObject str) {

@JRubyMethod(name = "inflate", required = 1, backtrace = true)
public IRubyObject inflate(ThreadContext context, IRubyObject string) {
if (internalFinished()) {
// follow CRuby's Zlib behavior: return empty String after finished inflating.
return RubyString.newEmptyString(context.getRuntime());
}
ByteList data = null;
if (!string.isNil()) {
data = string.convertToString().getByteList();
Expand Down
26 changes: 26 additions & 0 deletions test/test_zlib.rb
Expand Up @@ -269,4 +269,30 @@ def test_corrupted_data
end
end
end

def test_inflate_after_finish
z = Zlib::Inflate.new
data = "x\234c`\200\001\000\000\n\000\001"
unzipped = z.inflate data
z.finish # this is a precondition

out = z.inflate('uncompressed_data')
out << z.finish
assert_equal('uncompressed_data', out)
z << ('uncompressed_data') << nil
assert_equal('uncompressed_data', z.finish)
end

def test_inflate_pass_through
main_data = "x\234K\313\317\a\000\002\202\001E"
result = ""
z = Zlib::Inflate.new
# add bytes, one by one
(main_data * 2).each_byte { |d| result << z.inflate(d.chr)}
assert_equal("foo", result)
# the first chunk is inflated to its completion,
# the second chunk is just passed through.
result << z.finish
assert_equal("foo" + main_data, result)
end
end

0 comments on commit 34624c3

Please sign in to comment.