Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix for JRUBY-4503: recover pass-through behavior of Zlib::Inflate.

Signed-off-by: Vladimir Sizikov <vsizikov@gmail.com>
  • Loading branch information...
commit 34624c31c4affe1eac1aeb20035a2f50a3659bb9 1 parent 63b7f09
@nahi nahi authored headius committed
Showing with 26 additions and 4 deletions.
  1. +0 −4 src/org/jruby/RubyZlib.java
  2. +26 −0 test/test_zlib.rb
View
4 src/org/jruby/RubyZlib.java
@@ -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();
View
26 test/test_zlib.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.