diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index e325ecbdca..e73fb9e89f 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -617,7 +617,8 @@ module Formulary return unless path.expand_path.exist? return if Homebrew::EnvConfig.forbid_packages_from_paths? && - !path.realpath.to_s.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/") + !path.realpath.to_s.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", + "#{HOMEBREW_CACHE}/") if (tap = Tap.from_path(path)) # Only treat symlinks in taps as aliases. diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index c2457856d4..0bf3c933ef 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -141,6 +141,21 @@ RSpec.describe Formulary do end.to raise_error(FormulaUnavailableError) end + it "allows cache paths even when paths are disabled" do + ENV["HOMEBREW_FORBID_PACKAGES_FROM_PATHS"] = "1" + cache_dir = HOMEBREW_CACHE/"test_formula_cache" + cache_dir.mkpath + cache_formula_path = cache_dir/formula_path.basename + FileUtils.cp formula_path, cache_formula_path + begin + formula = described_class.factory(cache_formula_path) + expect(formula).to be_a(Formula) + ensure + cache_formula_path.unlink if cache_formula_path.exist? + cache_dir.rmdir if cache_dir.exist? + end + end + context "when given a bottle" do subject(:formula) { described_class.factory(bottle) }