ruby-changes:72796
From: David <ko1@a...>
Date: Wed, 3 Aug 2022 06:56:30 +0900 (JST)
Subject: [ruby-changes:72796] 20936eb3a9 (master): [rubygems/rubygems] Warn (rather than crash) when setting `nil` specification versions
https://git.ruby-lang.org/ruby.git/commit/?id=20936eb3a9 From 20936eb3a95f3564e565f59228a35453ae94eee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Mon, 1 Aug 2022 09:56:39 +0200 Subject: [rubygems/rubygems] Warn (rather than crash) when setting `nil` specification versions https://github.com/rubygems/rubygems/commit/a4ba1a4d97 --- lib/rubygems/specification.rb | 2 ++ lib/rubygems/version.rb | 14 +++++++++++--- test/rubygems/test_gem_requirement.rb | 12 +++++++++--- test/rubygems/test_gem_specification.rb | 9 +++++++++ test/rubygems/test_gem_version.rb | 11 +++++++++-- 5 files changed, 40 insertions(+), 8 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 https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L2653 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 https://github.com/ruby/ruby/blob/trunk/lib/rubygems/version.rb#L171 # 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 https://github.com/ruby/ruby/blob/trunk/lib/rubygems/version.rb#L188 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 https://github.com/ruby/ruby/blob/trunk/lib/rubygems/version.rb#L206 @@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. diff --git a/test/rubygems/test_gem_requirement.rb b/test/rubygems/test_gem_requirement.rb index 37137dbdad..5ecdbeddae 100644 --- a/test/rubygems/test_gem_requirement.rb +++ b/test/rubygems/test_gem_requirement.rb @@ -129,7 +129,9 @@ class TestGemRequirement < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_requirement.rb#L129 assert_satisfied_by "1.3", r assert_raise ArgumentError do - assert_satisfied_by nil, r + Gem::Deprecate.skip_during do + assert_satisfied_by nil, r + end end end @@ -141,7 +143,9 @@ class TestGemRequirement < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_requirement.rb#L143 refute_satisfied_by "1.3", r assert_raise ArgumentError do - assert_satisfied_by nil, r + Gem::Deprecate.skip_during do + assert_satisfied_by nil, r + end end end @@ -153,7 +157,9 @@ class TestGemRequirement < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_requirement.rb#L157 refute_satisfied_by "1.3", r assert_raise ArgumentError do - assert_satisfied_by nil, r + Gem::Deprecate.skip_during do + assert_satisfied_by nil, r + end end end diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 6117e81a81..cf0dba4331 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1220,6 +1220,15 @@ dependencies: [] https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_specification.rb#L1220 assert_equal "1.0.0.dev", spec.version.to_s end + def test_initialize_nil_version + expected = "nil versions are discouraged and will be deprecated in Rubygems 4\n" + actual_stdout, actual_stderr = capture_output do + Gem::Specification.new.version = nil + end + assert_empty actual_stdout + assert_equal(expected, actual_stderr) + end + def test__dump @a2.platform = Gem::Platform.local @a2.instance_variable_set :@original_platform, "old_platform" diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb index e907eabb34..9237608d4a 100644 --- a/test/rubygems/test_gem_version.rb +++ b/test/rubygems/test_gem_version.rb @@ -32,8 +32,15 @@ class TestGemVersion < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_version.rb#L32 def test_class_create real = Gem::Version.new(1.0) - assert_same real, Gem::Version.create(real) - assert_nil Gem::Version.create(nil) + assert_same real, Gem::Version.create(real) + + expected = "nil versions are discouraged and will be deprecated in Rubygems 4\n" + actual_stdout, actual_stderr = capture_output do + assert_nil Gem::Version.create(nil) + end + assert_empty actual_stdout + assert_equal(expected, actual_stderr) + assert_equal v("5.1"), Gem::Version.create("5.1") ver = "1.1".freeze -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/