summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2024-07-17 22:11:06 +0200
committergit <svn-admin@ruby-lang.org>2024-07-18 09:25:17 +0000
commit86c99a8d14daa15b1b5f6c99697630aa3abb7d5d (patch)
tree82a2feab9ca9086c8e5e333b5242193e268fd169
parent95728a8b4208bb9a3427cde95a4ceba76e349b39 (diff)
[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
-rw-r--r--lib/bundler/installer/standalone.rb3
-rw-r--r--lib/bundler/rubygems_ext.rb6
-rw-r--r--lib/rubygems/specification.rb2
-rw-r--r--spec/bundler/install/gems/standalone_spec.rb2
-rw-r--r--test/rubygems/test_gem_specification.rb12
5 files changed, 20 insertions, 5 deletions
diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb
index 5331df2e95..cf5993448c 100644
--- a/lib/bundler/installer/standalone.rb
+++ b/lib/bundler/installer/standalone.rb
@@ -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
diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb
index 3d53368659..2a18ce1c49 100644
--- a/lib/bundler/rubygems_ext.rb
+++ b/lib/bundler/rubygems_ext.rb
@@ -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"
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index ec2055c4ab..d0e0e4e91a 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -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
diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb
index f145679a33..08529f110c 100644
--- a/spec/bundler/install/gems/standalone_spec.rb
+++ b/spec/bundler/install/gems/standalone_spec.rb
@@ -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
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 71b2f1ca67..0a67dad25d 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -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