diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 8135629707..52728158a5 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -620,8 +620,8 @@ module Formulary path_realpath = path.realpath.to_s path_string = path.to_s if (path_realpath.end_with?(".rb") || path_string.end_with?(".rb")) && - !path_realpath.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", "#{HOMEBREW_CACHE}/") && - !path_string.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/") if path_string.include?("./") || path_string.end_with?(".rb") || path_string.count("/") != 2 raise <<~WARNING Homebrew requires formulae to be in a tap, rejecting: diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 3ab0bafb71..0f957e23e4 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -141,19 +141,26 @@ 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 + context "when given a cache path" do + let(:cache_dir) { HOMEBREW_CACHE/"test_formula_cache" } + let(:cache_formula_path) { cache_dir/formula_path.basename } + + before do + cache_dir.mkpath + FileUtils.cp formula_path, cache_formula_path + end + + after do cache_formula_path.unlink if cache_formula_path.exist? cache_dir.rmdir if cache_dir.exist? 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 context "when given a bottle" do