Merge pull request #20487 from Homebrew/formulary-forbid-cache

formulary: do not allow using the cache when forbidding paths
This commit is contained in:
Mike McQuaid 2025-08-18 15:54:34 +00:00 committed by GitHub
commit 0cadd6d0c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 12 deletions

View File

@ -620,8 +620,8 @@ module Formulary
path_realpath = path.realpath.to_s path_realpath = path.realpath.to_s
path_string = path.to_s path_string = path.to_s
if (path_realpath.end_with?(".rb") || path_string.end_with?(".rb")) && if (path_realpath.end_with?(".rb") || path_string.end_with?(".rb")) &&
!path_realpath.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", "#{HOMEBREW_CACHE}/") && !path_realpath.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/") &&
!path_string.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", "#{HOMEBREW_CACHE}/") !path_string.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/")
if path_string.include?("./") || path_string.end_with?(".rb") || path_string.count("/") != 2 if path_string.include?("./") || path_string.end_with?(".rb") || path_string.count("/") != 2
raise <<~WARNING raise <<~WARNING
Homebrew requires formulae to be in a tap, rejecting: Homebrew requires formulae to be in a tap, rejecting:

View File

@ -141,19 +141,26 @@ RSpec.describe Formulary do
end.to raise_error(FormulaUnavailableError) end.to raise_error(FormulaUnavailableError)
end end
it "allows cache paths even when paths are disabled" do context "when given a cache path" do
ENV["HOMEBREW_FORBID_PACKAGES_FROM_PATHS"] = "1" let(:cache_dir) { HOMEBREW_CACHE/"test_formula_cache" }
cache_dir = HOMEBREW_CACHE/"test_formula_cache" let(:cache_formula_path) { cache_dir/formula_path.basename }
cache_dir.mkpath
cache_formula_path = cache_dir/formula_path.basename before do
FileUtils.cp formula_path, cache_formula_path cache_dir.mkpath
begin FileUtils.cp formula_path, cache_formula_path
formula = described_class.factory(cache_formula_path) end
expect(formula).to be_a(Formula)
ensure after do
cache_formula_path.unlink if cache_formula_path.exist? cache_formula_path.unlink if cache_formula_path.exist?
cache_dir.rmdir if cache_dir.exist? cache_dir.rmdir if cache_dir.exist?
end end
it "disallows cache paths when paths are explicitly disabled" do
ENV["HOMEBREW_FORBID_PACKAGES_FROM_PATHS"] = "1"
expect do
described_class.factory(cache_formula_path)
end.to raise_error(/requires formulae to be in a tap/)
end
end end
context "when given a bottle" do context "when given a bottle" do