aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-28 14:26:47 +0900
committergit <svn-admin@ruby-lang.org>2023-07-30 01:36:23 +0000
commit0d86cc4caf1495507b2937654d3ed868278b9ddc (patch)
tree1d2fc052ac5e3c67aa766b8a43ff984ab73f82f0
parentbde4080b3989b4f097371b5cadb82bf6cb7c45b1 (diff)
downloadruby-0d86cc4caf1495507b2937654d3ed868278b9ddc.tar.gz
[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
-rw-r--r--lib/bundler/rubygems_integration.rb3
-rw-r--r--lib/rubygems/core_ext/kernel_require.rb3
-rw-r--r--spec/bundler/runtime/setup_spec.rb30
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