Skip to content

Commit efe22f2

Browse files
SeanLFsamuel-williams-shopify
authored andcommitted
Backport UploadedFile keyword forwarding fix
Backport the fix from rack#2482 to Rack 3.2, retaining ruby2_keywords because the stable branch supports Ruby 2.4.
1 parent 70d2e10 commit efe22f2

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file. For info on how to format all future additions to this file please reference [Keep A Changelog](https://keepachangelog.com/en/1.0.0/).
44

5+
## Unreleased
6+
7+
### Fixed
8+
9+
- `Rack::Multipart::UploadedFile` now delegates keyword arguments to the wrapped tempfile. Calls such as `uploaded_file.readlines(chomp: true)` raised `TypeError` on Ruby 3.0+. ([#2481](https://github.com/rack/rack/issues/2481), [@SeanLF](https://github.com/SeanLF))
10+
511
## [3.2.7] - 2026-08-13
612

713
### Fixed

lib/rack/multipart/uploaded_file.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def respond_to_missing?(*args)
7777
def method_missing(method_name, *args, &block) #:nodoc:
7878
@tempfile.__send__(method_name, *args, &block)
7979
end
80+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
8081
end
8182
end
8283
end

test/spec_multipart.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,13 @@ def initialize(*)
10191019
Rack::Multipart::UploadedFile.new(multipart_file("file1.txt"), binary: true).must_be :binmode?
10201020
end
10211021

1022+
it "delegates keyword arguments to the tempfile" do
1023+
file = Rack::Multipart::UploadedFile.new(multipart_file("file1.txt"))
1024+
file.readlines(chomp: true).must_equal ['contents']
1025+
file.rewind
1026+
file.gets(chomp: true).must_equal 'contents'
1027+
end
1028+
10221029
it "builds multipart body" do
10231030
files = Rack::Multipart::UploadedFile.new(multipart_file("file1.txt"))
10241031
data = Rack::Multipart.build_multipart("submit-name" => "Larry", "files" => files)

0 commit comments

Comments
 (0)