1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Warn (rather than crash) when setting nil specification versions

https://github.com/rubygems/rubygems/commit/a4ba1a4d97
This commit is contained in:
David Rodríguez 2022-08-01 09:56:39 +02:00 committed by git
parent eaf6189fe5
commit 20936eb3a9
5 changed files with 40 additions and 8 deletions

View file

@ -2653,6 +2653,8 @@ class Gem::Specification < Gem::BasicSpecification
def version=(version) def version=(version)
@version = Gem::Version.create(version) @version = Gem::Version.create(version)
return if @version.nil?
# skip to set required_ruby_version when pre-released rubygems. # skip to set required_ruby_version when pre-released rubygems.
# It caused to raise CircularDependencyError # It caused to raise CircularDependencyError
if @version.prerelease? && (@name.nil? || @name.strip != "rubygems") if @version.prerelease? && (@name.nil? || @name.strip != "rubygems")

View file

@ -171,9 +171,7 @@ class Gem::Version
# True if the +version+ string matches RubyGems' requirements. # True if the +version+ string matches RubyGems' requirements.
def self.correct?(version) def self.correct?(version)
unless Gem::Deprecate.skip nil_versions_are_discouraged! if version.nil?
warn "nil versions are discouraged and will be deprecated in Rubygems 4" if version.nil?
end
!!(version.to_s =~ ANCHORED_VERSION_PATTERN) !!(version.to_s =~ ANCHORED_VERSION_PATTERN)
end end
@ -190,6 +188,8 @@ class Gem::Version
if self === input # check yourself before you wreck yourself if self === input # check yourself before you wreck yourself
input input
elsif input.nil? elsif input.nil?
nil_versions_are_discouraged!
nil nil
else else
new input new input
@ -206,6 +206,14 @@ class Gem::Version
@@all[version] ||= super @@all[version] ||= super
end 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 # Constructs a Version from the +version+ string. A version string is a
# series of digits or ASCII letters separated by dots. # series of digits or ASCII letters separated by dots.

View file

@ -129,9 +129,11 @@ class TestGemRequirement < Gem::TestCase
assert_satisfied_by "1.3", r assert_satisfied_by "1.3", r
assert_raise ArgumentError do assert_raise ArgumentError do
Gem::Deprecate.skip_during do
assert_satisfied_by nil, r assert_satisfied_by nil, r
end end
end end
end
def test_satisfied_by_eh_blank def test_satisfied_by_eh_blank
r = req "1.2" r = req "1.2"
@ -141,9 +143,11 @@ class TestGemRequirement < Gem::TestCase
refute_satisfied_by "1.3", r refute_satisfied_by "1.3", r
assert_raise ArgumentError do assert_raise ArgumentError do
Gem::Deprecate.skip_during do
assert_satisfied_by nil, r assert_satisfied_by nil, r
end end
end end
end
def test_satisfied_by_eh_equal def test_satisfied_by_eh_equal
r = req "= 1.2" r = req "= 1.2"
@ -153,9 +157,11 @@ class TestGemRequirement < Gem::TestCase
refute_satisfied_by "1.3", r refute_satisfied_by "1.3", r
assert_raise ArgumentError do assert_raise ArgumentError do
Gem::Deprecate.skip_during do
assert_satisfied_by nil, r assert_satisfied_by nil, r
end end
end end
end
def test_satisfied_by_eh_gt def test_satisfied_by_eh_gt
r = req "> 1.2" r = req "> 1.2"

View file

@ -1220,6 +1220,15 @@ dependencies: []
assert_equal "1.0.0.dev", spec.version.to_s assert_equal "1.0.0.dev", spec.version.to_s
end 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 def test__dump
@a2.platform = Gem::Platform.local @a2.platform = Gem::Platform.local
@a2.instance_variable_set :@original_platform, "old_platform" @a2.instance_variable_set :@original_platform, "old_platform"

View file

@ -33,7 +33,14 @@ class TestGemVersion < Gem::TestCase
real = Gem::Version.new(1.0) real = Gem::Version.new(1.0)
assert_same real, Gem::Version.create(real) 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) 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") assert_equal v("5.1"), Gem::Version.create("5.1")
ver = "1.1".freeze ver = "1.1".freeze