Skip to content

Require pathname in FormData::File - #40

Merged
sferik merged 1 commit into
masterfrom
require-pathname
Oct 25, 2026
Merged

sferik merged 1 commit into
masterfrom
require-pathname

Conversation

@sferik

@sferik sferik commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

FormData::File checks for Pathnames and opens them, but nothing ever required pathname. Normally RubyGems has already loaded it, so nobody noticed. Without RubyGems, as with ruby --disable-gems, HTTP::FormData::File.new(StringIO.new("x")) raises NameError: uninitialized constant HTTP::FormData::File::Pathname. I could reproduce it on 3.2 and 3.4. Ruby 4.0 has Pathname in core, so it's fine there.

The fix is a one-line require "pathname". The test runs Ruby without RubyGems in a child process, because in the test process Pathname is always loaded already. It also clears RUBYOPT, since under bundle exec that carries -rbundler/setup, which loads Pathname and hid the bug. Without the fix, the test fails.

FormData::File checks for and opens Pathnames, but never required
pathname. RubyGems usually loads it first, so it only showed up with
--disable-gems, where File.new raised NameError on Ruby 3.4 and older.
Ruby 4.0 has Pathname in core.
@sferik
sferik merged commit 664bf90 into master Oct 25, 2026
8 checks passed
@sferik
sferik deleted the require-pathname branch October 25, 2026 18:54
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