Merge pull request #20306 from Homebrew/license-symbol-fix

Fix forbidding special license refs
This commit is contained in:
Bo Anderson 2025-07-25 00:02:11 +00:00 committed by GitHub
commit fec86a9488
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 3 deletions

View File

@ -1618,6 +1618,9 @@ on_request: installed_on_request?, options:)
invalid_licenses = []
forbidden_licenses = forbidden_licenses.split.each_with_object({}) do |license, hash|
license_sym = license.to_sym
license = license_sym if SPDX::ALLOWED_LICENSE_SYMBOLS.include?(license_sym)
unless SPDX.valid_license?(license)
invalid_licenses << license
next

View File

@ -255,6 +255,28 @@ RSpec.describe FormulaInstaller do
fi.forbidden_license_check
end.to raise_error(CannotInstallFormulaError, /dependency on #{dep_name} where all/)
end
it "raises on forbidden symbol license on formula" do
ENV["HOMEBREW_FORBIDDEN_LICENSES"] = "public_domain"
f_name = "homebrew-forbidden-license"
f_path = CoreTap.instance.new_formula_path(f_name)
f_path.write <<~RUBY
class #{Formulary.class_s(f_name)} < Formula
url "foo"
version "0.1"
license :public_domain
end
RUBY
Formulary.cache.delete(f_path)
f = Formulary.factory(f_name)
fi = described_class.new(f)
expect do
fi.forbidden_license_check
end.to raise_error(CannotInstallFormulaError, /#{f_name}'s licenses are all forbidden/)
end
end
describe "#forbidden_tap_check" do

View File

@ -229,13 +229,13 @@ module SPDX
end
sig {
params(license_expression: T.any(String, Symbol, T::Hash[Symbol, T.untyped]),
forbidden_licenses: T::Hash[Symbol, T.untyped]).returns(T::Boolean)
params(license_expression: T.any(String, Symbol, T::Hash[T.any(Symbol, String), T.untyped]),
forbidden_licenses: T::Hash[T.any(Symbol, String), T.untyped]).returns(T::Boolean)
}
def licenses_forbid_installation?(license_expression, forbidden_licenses)
case license_expression
when String, Symbol
forbidden_licenses_include? license_expression.to_s, forbidden_licenses
forbidden_licenses_include? license_expression, forbidden_licenses
when Hash
key = license_expression.keys.first
return false if key.nil?