Skip to content

Commit 406b9c0

Browse files
committed
Fix forbidding special license refs
1 parent a190b1f commit 406b9c0

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

Library/Homebrew/formula_installer.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,9 @@ def forbidden_license_check
16181618

16191619
invalid_licenses = []
16201620
forbidden_licenses = forbidden_licenses.split.each_with_object({}) do |license, hash|
1621+
license_sym = license.to_sym
1622+
license = license_sym if SPDX::ALLOWED_LICENSE_SYMBOLS.include?(license_sym)
1623+
16211624
unless SPDX.valid_license?(license)
16221625
invalid_licenses << license
16231626
next

Library/Homebrew/test/formula_installer_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,28 @@ class #{Formulary.class_s(f_name)} < Formula
255255
fi.forbidden_license_check
256256
end.to raise_error(CannotInstallFormulaError, /dependency on #{dep_name} where all/)
257257
end
258+
259+
it "raises on forbidden symbol license on formula" do
260+
ENV["HOMEBREW_FORBIDDEN_LICENSES"] = "public_domain"
261+
262+
f_name = "homebrew-forbidden-license"
263+
f_path = CoreTap.instance.new_formula_path(f_name)
264+
f_path.write <<~RUBY
265+
class #{Formulary.class_s(f_name)} < Formula
266+
url "foo"
267+
version "0.1"
268+
license :public_domain
269+
end
270+
RUBY
271+
Formulary.cache.delete(f_path)
272+
273+
f = Formulary.factory(f_name)
274+
fi = described_class.new(f)
275+
276+
expect do
277+
fi.forbidden_license_check
278+
end.to raise_error(CannotInstallFormulaError, /#{f_name}'s licenses are all forbidden/)
279+
end
258280
end
259281

260282
describe "#forbidden_tap_check" do

Library/Homebrew/utils/spdx.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,13 @@ def license_version_info(license)
229229
end
230230

231231
sig {
232-
params(license_expression: T.any(String, Symbol, T::Hash[Symbol, T.untyped]),
233-
forbidden_licenses: T::Hash[Symbol, T.untyped]).returns(T::Boolean)
232+
params(license_expression: T.any(String, Symbol, T::Hash[T.any(Symbol, String), T.untyped]),
233+
forbidden_licenses: T::Hash[T.any(Symbol, String), T.untyped]).returns(T::Boolean)
234234
}
235235
def licenses_forbid_installation?(license_expression, forbidden_licenses)
236236
case license_expression
237237
when String, Symbol
238-
forbidden_licenses_include? license_expression.to_s, forbidden_licenses
238+
forbidden_licenses_include? license_expression, forbidden_licenses
239239
when Hash
240240
key = license_expression.keys.first
241241
return false if key.nil?

0 commit comments

Comments
 (0)