diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 5d2bde7bf0..cf37d3eab4 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -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 diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb index d0b079efcf..a1cd97dc02 100644 --- a/Library/Homebrew/test/formula_installer_spec.rb +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -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 diff --git a/Library/Homebrew/utils/spdx.rb b/Library/Homebrew/utils/spdx.rb index 7b8e69e865..96c95aba7b 100644 --- a/Library/Homebrew/utils/spdx.rb +++ b/Library/Homebrew/utils/spdx.rb @@ -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?