diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2022-08-01 09:56:39 +0200 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-08-03 06:56:18 +0900 |
commit | 20936eb3a95f3564e565f59228a35453ae94eee3 (patch) | |
tree | 77b5764ec94ec8e6597e365219b61c250f38bcf5 /lib/rubygems | |
parent | eaf6189fe59ac4839d3a04bf7f9552fc22f09471 (diff) |
[rubygems/rubygems] Warn (rather than crash) when setting `nil` specification versions
https://github.com/rubygems/rubygems/commit/a4ba1a4d97
Diffstat (limited to 'lib/rubygems')
-rw-r--r-- | lib/rubygems/specification.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/version.rb | 14 |
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index f2e2740026..28ad176b53 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -2653,6 +2653,8 @@ class Gem::Specification < Gem::BasicSpecification def version=(version) @version = Gem::Version.create(version) + return if @version.nil? + # skip to set required_ruby_version when pre-released rubygems. # It caused to raise CircularDependencyError if @version.prerelease? && (@name.nil? || @name.strip != "rubygems") diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index 03ae5ca17e..bb41374ffc 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -171,9 +171,7 @@ class Gem::Version # True if the +version+ string matches RubyGems' requirements. def self.correct?(version) - unless Gem::Deprecate.skip - warn "nil versions are discouraged and will be deprecated in Rubygems 4" if version.nil? - end + nil_versions_are_discouraged! if version.nil? !!(version.to_s =~ ANCHORED_VERSION_PATTERN) end @@ -190,6 +188,8 @@ class Gem::Version if self === input # check yourself before you wreck yourself input elsif input.nil? + nil_versions_are_discouraged! + nil else new input @@ -206,6 +206,14 @@ class Gem::Version @@all[version] ||= super end + def self.nil_versions_are_discouraged! + unless Gem::Deprecate.skip + warn "nil versions are discouraged and will be deprecated in Rubygems 4" + end + end + + private_class_method :nil_versions_are_discouraged! + ## # Constructs a Version from the +version+ string. A version string is a # series of digits or ASCII letters separated by dots. |