Skip to content

Delegate keyword arguments in UploadedFile#method_missing - #2482

Closed
SeanLF wants to merge 2 commits into
rack:mainfrom
SeanLF:fix-uploaded-file-kwargs
Closed

SeanLF wants to merge 2 commits into
rack:mainfrom
SeanLF:fix-uploaded-file-kwargs

Conversation

@SeanLF

@SeanLF SeanLF commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #2481.

Rack::Multipart::UploadedFile#method_missing delegates to the wrapped tempfile but was never flagged with ruby2_keywords, so keyword arguments are rebuilt as a positional Hash on Ruby 3.0+:

uf.readlines(chomp: true)  # => TypeError: no implicit conversion of Hash into Integer
uf.gets(chomp: true)       # => TypeError: no implicit conversion of Hash into Integer

This flags the delegator, matching BodyProxy#method_missing and MockResponse::Cookie#method_missing.

Ruby 2.4 to 2.6 are unaffected either way, since they do not distinguish a trailing Hash from keywords. The respond_to? guard is kept because ruby2_keywords does not exist before 2.7.

The added test fails without the change (TypeError) and passes with it. Verified on Ruby 2.4.10, 2.6.10, 3.0.7 and 4.0.6.

Rack::Multipart::UploadedFile forwards missing methods to the wrapped
tempfile, but the delegator was never flagged with ruby2_keywords. On Ruby
3.0+, where keywords are separated from a trailing Hash, the keywords are
rebuilt as a positional Hash before reaching the tempfile:

  uploaded_file.readlines(chomp: true)
  # => TypeError: no implicit conversion of Hash into Integer
  uploaded_file.gets(chomp: true)
  # => TypeError: no implicit conversion of Hash into Integer

Ruby 2.4 through 2.6 are unaffected, since they do not distinguish a
trailing Hash from keywords, which is why this went unnoticed.

Flag the delegator, matching BodyProxy#method_missing and
MockResponse::Cookie#method_missing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@jeremyevans jeremyevans left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you for the patch.

In the future, if you have a fix prepared, it's best to submit just the pull request and not file a separate GitHub issue.

@SeanLF

SeanLF commented Jul 27, 2026

Copy link
Copy Markdown
Author

Understood, thanks. Follow-up in #2484 (draft, stacked on this one).

Comment thread lib/rack/multipart/uploaded_file.rb Outdated
The trailing conditional means the line itself is always executed, so line
coverage records a hit regardless of whether ruby2_keywords is called. The
markers were suppressing nothing.

Verified hit count of 1 on 2.6 (guard false, call skipped), 3.0 and 4.0.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@ioquatix ioquatix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@samuel-williams-shopify

Copy link
Copy Markdown
Collaborator

Merged in #2499

samuel-williams-shopify pushed a commit to socketry/rack that referenced this pull request Aug 14, 2026
Backport the fix from rack#2482 to Rack 3.2, retaining ruby2_keywords because the stable branch supports Ruby 2.4.
samuel-williams-shopify added a commit that referenced this pull request Aug 14, 2026
Backport the fix from #2482 to Rack 3.2, retaining ruby2_keywords because the stable branch supports Ruby 2.4.

Co-authored-by: Sean Floyd <[email protected]>
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.

UploadedFile#method_missing drops keyword arguments on Ruby 3.0+

4 participants