[rubygems/rubygems] Make nil a valid license spec

https://github.com/rubygems/rubygems/commit/675effb67e
This commit is contained in:
John Hong 2023-08-17 22:06:37 -04:00 committed by git
parent 4524aeba2f
commit 744bc4d5d0
3 changed files with 33 additions and 11 deletions

View File

@ -343,7 +343,7 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use:
String
end
unless Array === val && val.all? {|x| x.is_a?(klass) }
unless Array === val && val.all? {|x| x.is_a?(klass) || (field == :licenses && x.nil?) }
error "#{field} must be an Array of #{klass}"
end
end
@ -358,6 +358,8 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use:
licenses = @specification.licenses
licenses.each do |license|
next if license.nil?
if license.length > 64
error "each license must be 64 characters or less"
end
@ -368,11 +370,12 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use:
licenses = @specification.licenses
licenses.each do |license|
next if Gem::Licenses.match?(license)
next if Gem::Licenses.match?(license) || license.nil?
suggestions = Gem::Licenses.suggestions(license)
message = <<-WARNING
license value '#{license}' is invalid. Use a license identifier from
http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license.
http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license,
or set it to nil if you don't want to specify a license.
WARNING
message += "Did you mean #{suggestions.map {|s| "'#{s}'" }.join(", ")}?\n" unless suggestions.nil?
warning(message)
@ -380,7 +383,8 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li
warning <<-WARNING if licenses.empty?
licenses is empty, but is recommended. Use a license identifier from
http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license.
http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard license,
or set it to nil if you don't want to specify a license.
WARNING
end

View File

@ -199,7 +199,8 @@ class TestGemCommandsBuildCommand < Gem::TestCase
error = @ui.error.split "\n"
assert_equal "WARNING: licenses is empty, but is recommended. Use a license identifier from", error.shift
assert_equal "http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.", error.shift
assert_equal "http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,", error.shift
assert_equal "or set it to nil if you don't want to specify a license.", error.shift
assert_equal "WARNING: See https://guides.rubygems.org/specification-reference/ for help", error.shift
assert_equal [], error

View File

@ -3086,10 +3086,22 @@ Please report a bug if this causes problems.
assert_match <<-WARNING, @ui.error
WARNING: licenses is empty, but is recommended. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
or set it to nil if you don't want to specify a license.
WARNING
end
def test_validate_nil_license
util_setup_validate
use_ui @ui do
@a1.license = nil
@a1.validate
end
assert_empty @ui.error
end
def test_validate_license_in_a_non_packaging_context
util_setup_validate
@ -3126,7 +3138,8 @@ http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
assert_match <<-WARNING, @ui.error
WARNING: license value 'BSD' is invalid. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
or set it to nil if you don't want to specify a license.
WARNING
end
@ -3184,11 +3197,13 @@ http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
assert_match <<-WARNING, @ui.error
WARNING: license value 'GPL-2.0+ FOO' is invalid. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
or set it to nil if you don't want to specify a license.
WARNING
assert_match <<-WARNING, @ui.error
WARNING: license value 'GPL-2.0 FOO' is invalid. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
or set it to nil if you don't want to specify a license.
WARNING
end
@ -3202,7 +3217,8 @@ http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
assert_match <<-WARNING, @ui.error
WARNING: license value 'GPL-2.0+ WITH Autocofn-exception-2.0' is invalid. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
or set it to nil if you don't want to specify a license.
WARNING
end
@ -3216,7 +3232,8 @@ http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
assert_match <<-WARNING, @ui.error
WARNING: license value 'ruby' is invalid. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
or set it to nil if you don't want to specify a license.
Did you mean 'Ruby'?
WARNING
end