From d4ac5c573b3b57dc4e62b684be297269defceba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 26 Sep 2024 11:22:19 +0200 Subject: [PATCH] [rubygems/rubygems] Don't add duplicated specs to unresolved specs This could happen when a regular gem shadows a default gem. https://github.com/rubygems/rubygems/commit/9ef70dd1f7 --- lib/rubygems/specification.rb | 2 +- test/rubygems/test_require.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index d05df9cf04..e5541e57b1 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -1412,7 +1412,7 @@ class Gem::Specification < Gem::BasicSpecification end begin - specs = spec_dep.to_specs + specs = spec_dep.to_specs.uniq(&:full_name) rescue Gem::MissingSpecError => e raise Gem::MissingSpecError.new(e.name, e.requirement, "at: #{spec_file}") end diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index b915a86197..48d66736fd 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -182,6 +182,22 @@ class TestGemRequire < Gem::TestCase assert_equal %w[a-1 b-1], loaded_spec_names end + def test_require_is_not_lazy_with_shadowed_default_gem + b1_default = new_default_spec("b", "1", nil, "foo.rb") + install_default_gems b1_default + + a1 = util_spec "a", "1", { "b" => ">= 1" }, "lib/test_gem_require_a.rb" + b1 = util_spec("b", "1", nil, "lib/foo.rb") + install_specs b1, a1 + + # Load default ruby gems fresh as if we've just started a ruby script. + Gem::Specification.reset + + assert_require "test_gem_require_a" + assert_equal %w[a-1 b-1], loaded_spec_names + assert_equal unresolved_names, [] + end + def test_require_is_lazy_with_inexact_req a1 = util_spec "a", "1", { "b" => ">= 1" }, "lib/test_gem_require_a.rb" b1 = util_spec "b", "1", nil, "lib/b/c.rb"