Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix zlib encoding #7334

Merged
merged 1 commit into from Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -650,6 +650,10 @@ public static RubyString newEmptyString(Ruby runtime) {
return newEmptyString(runtime, runtime.getString());
}

public static RubyString newEmptyBinaryString(Ruby runtime) {
return newAllocatedString(runtime, runtime.getString());
}

private static final ByteList EMPTY_ASCII8BIT_BYTELIST = new ByteList(ByteList.NULL_ARRAY, ASCIIEncoding.INSTANCE);
private static final ByteList EMPTY_USASCII_BYTELIST = new ByteList(ByteList.NULL_ARRAY, USASCIIEncoding.INSTANCE);

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ext/zlib/JZlibDeflate.java
Expand Up @@ -281,7 +281,7 @@ private void append(ByteList obj) throws IOException {
private IRubyObject flush(int flush) {
int last_flush = this.flush;
this.flush = flush;
if (flush == JZlib.Z_NO_FLUSH) return RubyString.newEmptyString(getRuntime());
if (flush == JZlib.Z_NO_FLUSH) return RubyString.newEmptyBinaryString(getRuntime());

run();
this.flush = last_flush;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ext/zlib/JZlibInflate.java
Expand Up @@ -108,7 +108,7 @@ private IRubyObject flushOutput(ThreadContext context, Block block) {
}
return res;
}
return RubyString.newEmptyString(context.runtime);
return RubyString.newEmptyBinaryString(context.runtime);
}

@JRubyMethod(name = "<<", required = 1)
Expand Down
Expand Up @@ -332,7 +332,7 @@ public IRubyObject read(ThreadContext context, IRubyObject[] args) {
return runtime.newString(buf);
}

return RubyString.newEmptyString(runtime);
return RubyString.newEmptyBinaryString(runtime);
} catch (IOException ioe) {
String m = ioe.getMessage();

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ext/zlib/ZStream.java
Expand Up @@ -77,7 +77,7 @@ public IRubyObject initialize(Block unusedBlock) {

@JRubyMethod
public IRubyObject flush_next_out(ThreadContext context, Block block) {
return RubyString.newEmptyString(context.getRuntime());
return RubyString.newEmptyBinaryString(context.getRuntime());
}

@JRubyMethod
Expand Down Expand Up @@ -145,7 +145,7 @@ public IRubyObject avail_in() {

@JRubyMethod(name = "flush_next_in")
public IRubyObject flush_next_in(ThreadContext context) {
return RubyString.newEmptyString(context.getRuntime());
return RubyString.newEmptyBinaryString(context.getRuntime());
}

@JRubyMethod(name = "total_in")
Expand Down