Skip to content

Pass keywords through in Zlib::GzipReader.zcat - #193

Open
ksss wants to merge 1 commit into
ruby:masterfrom
ksss:zcat-pass-keywords
Open

ksss wants to merge 1 commit into
ruby:masterfrom
ksss:zcat-pass-keywords

Conversation

@ksss

@ksss ksss commented Nov 21, 2026

Copy link
Copy Markdown

Zlib::GzipReader.zcat(io, options = {}) is documented to take options, but passing any raises:

Zlib::GzipReader.zcat(io, external_encoding: "UTF-8")
# => ArgumentError: wrong number of arguments (given 2, expected 1)

zcat forwards its arguments to GzipReader.new with rb_funcallv, which does not mark the trailing hash as keywords. Ruby 2.7's rb_scan_args still treated it as keywords (with a deprecation warning), but since the Ruby 3.0 keyword separation GzipReader#initialize (rb_scan_args(argc, argv, "1:", ...)) rejects it as an extra positional argument. The existing test only calls zcat without options, so this went unnoticed.

This uses rb_funcallv_kw(..., RB_PASS_CALLED_KEYWORDS), as gzfile_wrap already does for wrap/open, and adds a test for zcat with external_encoding:, with and without a block.

🤖 Generated with Claude Code

zcat forwards its arguments to GzipReader.new with rb_funcallv, which
does not mark the options hash as keywords. Since Ruby 3.0 the keyword
separation makes GzipReader#initialize reject it as an extra positional
argument, so the documented `options` always raised ArgumentError:

    Zlib::GzipReader.zcat(io, external_encoding: "UTF-8")
    # => ArgumentError: wrong number of arguments (given 2, expected 1)

Use rb_funcallv_kw with RB_PASS_CALLED_KEYWORDS, as gzfile_wrap does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant