From d767da428c28b7b9fec56b383bb32f6f76c6ad26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 4 Feb 2020 17:26:28 +0100 Subject: [rubygems/rubygems] Fix require issue with file extension priority If `require "a"` is run when two folders have been specified in the -I option including a "a.rb" file and a "a.so" file respectively, the ruby spec says that the ".rb" file should always be preferred. However, the logic we added in https://github.com/rubygems/rubygems/commit/6b81076d9 to make the -I option always beat default gems does not respect this spec, creating a difference from the original ruby-core's require. [the ruby spec says]: https://github.com/ruby/spec/blob/d80a6e2b221d4f17a8cadcac75ef950c59cba901/core/kernel/shared/require.rb#L234-L246 https://github.com/rubygems/rubygems/commit/b3944384f4 --- lib/rubygems/core_ext/kernel_require.rb | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'lib/rubygems/core_ext') diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index 60f4d18712..369f2c743e 100644 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -43,18 +43,18 @@ module Kernel # https://github.com/rubygems/rubygems/pull/1868 resolved_path = begin rp = nil - $LOAD_PATH[0...Gem.load_path_insert_index || -1].each do |lp| - safe_lp = lp.dup.tap(&Gem::UNTAINT) - begin - if File.symlink? safe_lp # for backward compatibility - next + Gem.suffixes.each do |s| + $LOAD_PATH[0...Gem.load_path_insert_index || -1].each do |lp| + safe_lp = lp.dup.tap(&Gem::UNTAINT) + begin + if File.symlink? safe_lp # for backward compatibility + next + end + rescue SecurityError + RUBYGEMS_ACTIVATION_MONITOR.exit + raise end - rescue SecurityError - RUBYGEMS_ACTIVATION_MONITOR.exit - raise - end - Gem.suffixes.each do |s| full_path = File.expand_path(File.join(safe_lp, "#{path}#{s}")) if File.file?(full_path) rp = full_path @@ -67,12 +67,8 @@ module Kernel end if resolved_path - begin - RUBYGEMS_ACTIVATION_MONITOR.exit - return gem_original_require(resolved_path) - rescue LoadError - RUBYGEMS_ACTIVATION_MONITOR.enter - end + RUBYGEMS_ACTIVATION_MONITOR.exit + return gem_original_require(resolved_path) end if spec = Gem.find_unresolved_default_spec(path) -- cgit v1.2.3