diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 1ff0ab1712..f8b2d12887 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -1139,11 +1139,12 @@ class FormulaInstaller end def forbidden_license_check - forbidden_licenses = Homebrew::EnvConfig.forbidden_licenses - .to_s - .sub("Public Domain", "public_domain") - .split(" ") - .to_h do |license| + forbidden_licenses = Homebrew::EnvConfig.forbidden_licenses.to_s + SPDX::ALLOWED_LICENSE_SYMBOLS.each do |s| + pattern = /#{s.to_s.tr("_", " ")}/i + forbidden_licenses = forbidden_licenses.sub(pattern, s.to_s) + end + forbidden_licenses = forbidden_licenses.split(" ").to_h do |license| [license, SPDX.license_version_info(license)] end diff --git a/Library/Homebrew/test/utils/spdx_spec.rb b/Library/Homebrew/test/utils/spdx_spec.rb index 5530a27b4e..40045647f9 100644 --- a/Library/Homebrew/test/utils/spdx_spec.rb +++ b/Library/Homebrew/test/utils/spdx_spec.rb @@ -91,6 +91,10 @@ describe SPDX do it "returns :public_domain" do expect(described_class.parse_license_expression(:public_domain).first).to eq [:public_domain] end + + it "returns :cannot_represent" do + expect(described_class.parse_license_expression(:cannot_represent).first).to eq [:cannot_represent] + end end describe ".valid_license?" do @@ -113,6 +117,14 @@ describe SPDX do it "returns true for :public_domain" do expect(described_class.valid_license?(:public_domain)).to eq true end + + it "returns true for :cannot_represent" do + expect(described_class.valid_license?(:cannot_represent)).to eq true + end + + it "returns false for invalid symbol" do + expect(described_class.valid_license?(:invalid_symbol)).to eq false + end end describe ".deprecated_license?" do @@ -131,6 +143,10 @@ describe SPDX do it "returns false for :public_domain" do expect(described_class.deprecated_license?(:public_domain)).to eq false end + + it "returns false for :cannot_represent" do + expect(described_class.deprecated_license?(:cannot_represent)).to eq false + end end describe ".valid_license_exception?" do @@ -187,9 +203,13 @@ describe SPDX do it "returns :public_domain" do expect(described_class.license_expression_to_string(:public_domain)).to eq "Public Domain" end + + it "returns :cannot_represent" do + expect(described_class.license_expression_to_string(:cannot_represent)).to eq "Cannot Represent" + end end - describe ".license_version_info_info" do + describe ".license_version_info" do it "returns license without version" do expect(described_class.license_version_info("MIT")).to eq ["MIT"] end diff --git a/Library/Homebrew/utils/spdx.rb b/Library/Homebrew/utils/spdx.rb index 3ae60ea72c..65a307770f 100644 --- a/Library/Homebrew/utils/spdx.rb +++ b/Library/Homebrew/utils/spdx.rb @@ -15,6 +15,10 @@ module SPDX DATA_PATH = (HOMEBREW_DATA_PATH/"spdx").freeze API_URL = "https://api.github.com/repos/spdx/license-list-data/releases/latest" + ALLOWED_LICENSE_SYMBOLS = [ + :public_domain, + :cannot_represent, + ].freeze def license_data @license_data ||= JSON.parse (DATA_PATH/"spdx_licenses.json").read @@ -64,14 +68,14 @@ module SPDX end def valid_license?(license) - return true if license == :public_domain + return ALLOWED_LICENSE_SYMBOLS.include? license if license.is_a? Symbol license = license.delete_suffix "+" license_data["licenses"].any? { |spdx_license| spdx_license["licenseId"] == license } end def deprecated_license?(license) - return false if license == :public_domain + return false if ALLOWED_LICENSE_SYMBOLS.include? license return false unless valid_license?(license) license_data["licenses"].none? do |spdx_license| @@ -89,8 +93,8 @@ module SPDX case license_expression when String license_expression - when :public_domain - "Public Domain" + when Symbol + license_expression.to_s.tr("_", " ").titleize when Hash expressions = [] @@ -125,7 +129,7 @@ module SPDX end def license_version_info(license) - return [license] if license == :public_domain + return [license] if ALLOWED_LICENSE_SYMBOLS.include? license match = license.match(/-(?[0-9.]+)(?:-.*?)??(?\+|-only|-or-later)?$/) return [license] if match.blank?