From 32ee4845d2f66c79b9f27cedbecf00a8476e71ce Mon Sep 17 00:00:00 2001 From: Erik Berlin Date: Sun, 25 Oct 2026 11:52:37 -0700 Subject: [PATCH] Require pathname in FormData::File 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. --- CHANGELOG.md | 5 +++++ lib/http/form_data/file.rb | 2 ++ test/http/form_data/file_test.rb | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0493249..25d50f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- `FormData::File` raised `NameError` on Ruby 3.4 and older when nothing + else had loaded Pathname, for example with `--disable-gems`. + ## [3.0.1] - 2026-03-20 ### Changed diff --git a/lib/http/form_data/file.rb b/lib/http/form_data/file.rb index 2b4b9d6..7cd2635 100644 --- a/lib/http/form_data/file.rb +++ b/lib/http/form_data/file.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "pathname" + module HTTP module FormData # Represents file form param. diff --git a/test/http/form_data/file_test.rb b/test/http/form_data/file_test.rb index 16852cc..521d032 100644 --- a/test/http/form_data/file_test.rb +++ b/test/http/form_data/file_test.rb @@ -35,6 +35,15 @@ def each_source public + # Pathname is only part of core Ruby from 4.0, and RubyGems usually + # loads it, so this checks in a process without RubyGems. + def test_loads_without_rubygems + lib = File.expand_path("../../../lib", __dir__) + code = 'require "stringio"; require "http/form_data"; HTTP::FormData::File.new(StringIO.new("x"))' + + assert system({ "RUBYOPT" => nil }, RbConfig.ruby, "--disable-gems", "-I", lib, "-e", code, err: File::NULL) + end + # --- Core Readable behavior across IO sources --- def test_size