[rubygems/rubygems] Fix gemspec require_paths type validation

It was not properly being detected as an Array attribute, and thus not
properly validated.

Fixing this allows us to remove a strange `rescue` clause in Bundler.

https://github.com/rubygems/rubygems/commit/4121a32408
This commit is contained in:
David Rodríguez 2024-07-17 22:11:06 +02:00 committed by git
parent 95728a8b42
commit 86c99a8d14
5 changed files with 20 additions and 5 deletions

View File

@ -58,9 +58,6 @@ module Bundler
else
SharedHelpers.relative_path_to(full_path, from: Bundler.root.join(bundler_path))
end
rescue TypeError
error_message = "#{spec.name} #{spec.version} has an invalid gemspec"
raise Gem::InvalidSpecificationException.new(error_message)
end
def prevent_gem_activation

View File

@ -60,6 +60,12 @@ module Gem
FLATTENS_REQUIRED_PATHS = Specification.new.respond_to?(:flatten_require_paths).freeze
class Specification
# Can be removed once RubyGems 3.5.15 support is dropped
correct_array_attributes = @@default_value.select {|_k,v| v.is_a?(Array) }.keys
unless @@array_attributes == correct_array_attributes
@@array_attributes = correct_array_attributes # rubocop:disable Style/ClassVars
end
require_relative "match_metadata"
require_relative "match_platform"

View File

@ -175,7 +175,7 @@ class Gem::Specification < Gem::BasicSpecification
end
@@attributes = @@default_value.keys.sort_by(&:to_s)
@@array_attributes = @@default_value.reject {|_k,v| v != [] }.keys
@@array_attributes = @@default_value.select {|_k,v| v.is_a?(Array) }.keys
@@nil_attributes, @@non_nil_attributes = @@default_value.keys.partition do |k|
@@default_value[k].nil?
end

View File

@ -295,7 +295,7 @@ RSpec.shared_examples "bundle install --standalone" do
it "outputs a helpful error message" do
expect(err).to include("You have one or more invalid gemspecs that need to be fixed.")
expect(err).to include("bar 1.0 has an invalid gemspec")
expect(err).to include("bar.gemspec is not valid")
end
end

View File

@ -2989,6 +2989,18 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use:
e.message
end
def test_validate_require_paths_with_invalid_types
util_setup_validate
@a1.require_paths = [1, 2]
e = assert_raise Gem::InvalidSpecificationException do
@a1.validate
end
assert_equal "require_paths must be an Array of String",
e.message
end
def test_validate_files
pend "test_validate_files skipped on MS Windows (symlink)" if Gem.win_platform?
util_setup_validate