[rubygems/rubygems] Stop allowing calling #gem on random objects

4b8570ae15
This commit is contained in:
David Rodríguez 2025-07-02 10:39:12 +02:00 committed by Hiroshi SHIBATA
parent 845e878f88
commit 6a5808965b
6 changed files with 1 additions and 27 deletions

View file

@ -33,7 +33,6 @@ module Bundler
settings_flag(:global_gem_cache) { bundler_4_mode? } settings_flag(:global_gem_cache) { bundler_4_mode? }
settings_flag(:lockfile_checksums) { bundler_4_mode? } settings_flag(:lockfile_checksums) { bundler_4_mode? }
settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") } settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") }
settings_flag(:setup_makes_kernel_gem_public) { !bundler_4_mode? }
settings_flag(:update_requires_all_flag) { bundler_5_mode? } settings_flag(:update_requires_all_flag) { bundler_5_mode? }
settings_option(:default_cli_command) { bundler_4_mode? ? :cli_help : :install } settings_option(:default_cli_command) { bundler_4_mode? ? :cli_help : :install }

View file

@ -161,9 +161,6 @@ The number of redirects allowed for network requests\. Defaults to \fB5\fR\.
\fBretry\fR (\fBBUNDLE_RETRY\fR) \fBretry\fR (\fBBUNDLE_RETRY\fR)
The number of times to retry failed network requests\. Defaults to \fB3\fR\. The number of times to retry failed network requests\. Defaults to \fB3\fR\.
.TP .TP
\fBsetup_makes_kernel_gem_public\fR (\fBBUNDLE_SETUP_MAKES_KERNEL_GEM_PUBLIC\fR)
Have \fBBundler\.setup\fR make the \fBKernel#gem\fR method public, even though RubyGems declares it as private\.
.TP
\fBshebang\fR (\fBBUNDLE_SHEBANG\fR) \fBshebang\fR (\fBBUNDLE_SHEBANG\fR)
The program name that should be invoked for generated binstubs\. Defaults to the ruby install name used to generate the binstub\. The program name that should be invoked for generated binstubs\. Defaults to the ruby install name used to generate the binstub\.
.TP .TP

View file

@ -180,9 +180,6 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html).
The number of redirects allowed for network requests. Defaults to `5`. The number of redirects allowed for network requests. Defaults to `5`.
* `retry` (`BUNDLE_RETRY`): * `retry` (`BUNDLE_RETRY`):
The number of times to retry failed network requests. Defaults to `3`. The number of times to retry failed network requests. Defaults to `3`.
* `setup_makes_kernel_gem_public` (`BUNDLE_SETUP_MAKES_KERNEL_GEM_PUBLIC`):
Have `Bundler.setup` make the `Kernel#gem` method public, even though
RubyGems declares it as private.
* `shebang` (`BUNDLE_SHEBANG`): * `shebang` (`BUNDLE_SHEBANG`):
The program name that should be invoked for generated binstubs. Defaults to The program name that should be invoked for generated binstubs. Defaults to
the ruby install name used to generate the binstub. the ruby install name used to generate the binstub.

View file

@ -214,9 +214,6 @@ module Bundler
e.requirement = dep.requirement e.requirement = dep.requirement
raise e raise e
end end
# backwards compatibility shim, see https://github.com/rubygems/bundler/issues/5102
kernel_class.send(:public, :gem) if Bundler.feature_flag.setup_makes_kernel_gem_public?
end end
end end

View file

@ -37,7 +37,6 @@ module Bundler
path.system path.system
plugins plugins
prefer_patch prefer_patch
setup_makes_kernel_gem_public
silence_deprecations silence_deprecations
silence_root_warning silence_root_warning
update_requires_all_flag update_requires_all_flag

View file

@ -1524,22 +1524,7 @@ end
end end
describe "after setup" do describe "after setup" do
it "allows calling #gem on random objects" do it "keeps Kernel#gem private" do
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack"
G
ruby <<-RUBY
require "bundler/setup"
Object.new.gem "myrack"
puts Gem.loaded_specs["myrack"].full_name
RUBY
expect(out).to eq("myrack-1.0.0")
end
it "keeps Kernel#gem private", bundler: "4" do
install_gemfile <<-G install_gemfile <<-G
source "https://gem.repo1" source "https://gem.repo1"
gem "myrack" gem "myrack"