Skip to content

Fix Interoperability with Zlib::GzipReader - #1082

Merged
byroot merged 1 commit into
ruby:masterfrom
moonglum:zlib-interop
Sep 30, 2026
Merged

byroot merged 1 commit into
ruby:masterfrom
moonglum:zlib-interop

Conversation

@moonglum

@moonglum moonglum commented Sep 30, 2026 •

Copy link
Copy Markdown

GzipReader offers both a read and to_io method. The read method returns the uncompressed file as a string. The to_io method returns the compressed file. The JSON.load method first tests for the to_io method and uses it before testing for the read method. This results in reading the compressed file, which is invalid JSON.

Instead, we now test for the read method first.

I added a test that fails on the current master branch to demonstrate the problem.

GzipReader offers both a read and to_io method. The read method returns
the uncompressed file as a string. The to_io method returns the
compressed file. The JSON.load method first tests for the to_io method
and uses it before testing for the read method. This results in reading
the compressed file, which is invalid JSON.

Instead, we now test for the read method first.
@byroot
byroot merged commit b6a5d35 into ruby:master Sep 30, 2026
42 checks passed
@moonglum
moonglum deleted the zlib-interop branch September 30, 2026 14:26
@moonglum

Copy link
Copy Markdown
Author

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants