From 0d86cc4caf1495507b2937654d3ed868278b9ddc Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 28 Jul 2023 14:26:47 +0900 Subject: [rubygems/rubygems] Use the dedicated method to convert file path The dedicated method `File.path` to deal with pathname-like objects has been provided since ruby 1.9.0. Also adds a test for rubygems/rubygems#6837. https://github.com/rubygems/rubygems/commit/258c6eda80 --- lib/bundler/rubygems_integration.rb | 3 ++- lib/rubygems/core_ext/kernel_require.rb | 3 +-- spec/bundler/runtime/setup_spec.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index af749f8d10..bb7392bad4 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -245,7 +245,8 @@ module Bundler [::Kernel.singleton_class, ::Kernel].each do |kernel_class| kernel_class.send(:alias_method, :no_warning_require, :require) kernel_class.send(:define_method, :require) do |file| - name = file.to_s.tr("/", "-") + file = File.path(file) + name = file.tr("/", "-") if (::Gem::BUNDLED_GEMS::SINCE.keys - specs.to_a.map(&:name)).include?(name) unless $LOADED_FEATURES.any? {|f| f.end_with?("#{name}.rb", "#{name}.#{RbConfig::CONFIG["DLEXT"]}") } target_file = begin diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index 0f01d22c29..ddb44276eb 100644 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -37,8 +37,7 @@ module Kernel return gem_original_require(path) unless Gem.discover_gems_on_require RUBYGEMS_ACTIVATION_MONITOR.synchronize do - path = path.to_path if path.respond_to? :to_path - path = String.try_convert(path) || path + path = File.path(path) if spec = Gem.find_unresolved_default_spec(path) # Ensure -I beats a default gem diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index e98d462ee6..09f179c517 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -1650,4 +1650,34 @@ end expect(err).to include("net-imap is not part of the default gems") end + + it "calls #to_path on the name to require" do + build_repo4 do + build_gem "net-imap" do |s| + s.write "lib/net/imap.rb", "NET_IMAP = '0.0.1'" + end + build_gem "csv" + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem "csv" + G + + ruby <<-R + Gem.send(:remove_const, :BUNDLED_GEMS) if defined?(Gem::BUNDLED_GEMS) + module Gem::BUNDLED_GEMS + SINCE = { "csv" => "1.0.0", "net-imap" => "0.0.1" } + end + path = BasicObject.new + def path.to_path; 'net/imap'; end + require 'bundler/setup' + begin + require path + rescue LoadError + end + R + + expect(err).to include("net-imap is not part of the default gems") + end end -- cgit v1.2.3