formulary: improve/loosen path rejection logic.

- Don't check if the `realpath` includes `/`: it always will.
  Instead, see if the originally user-passed `ref` includes `/` or ends
  with `.rb`.
- Always raise an error message, don't silently return.
This commit is contained in:
Mike McQuaid 2025-08-14 08:41:35 +01:00
parent 10b9da2d4d
commit c00413f0e9
No known key found for this signature in database

View File

@ -618,10 +618,11 @@ module Formulary
if Homebrew::EnvConfig.forbid_packages_from_paths? if Homebrew::EnvConfig.forbid_packages_from_paths?
path_realpath = path.realpath.to_s path_realpath = path.realpath.to_s
unless path_realpath.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", path_string = path.to_s
"#{HOMEBREW_CACHE}/") if !path_realpath.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", "#{HOMEBREW_CACHE}/") &&
raise <<~WARNING if path_realpath.include?("/") || path_realpath.end_with?(".rb") (path_string.include?("/") || path_string.end_with?(".rb"))
Rejecting formula at #{path_realpath} because it's not in a tap. raise <<~WARNING
Rejecting formula at #{!path_realpath} because it's not in a tap.
Homebrew requires formulae to be in a tap. Homebrew requires formulae to be in a tap.
To create a tap, run e.g. To create a tap, run e.g.
@ -629,8 +630,6 @@ module Formulary
To create a formula in a tap run e.g. To create a formula in a tap run e.g.
brew create <url> --tap=<user|org>/<repository> brew create <url> --tap=<user|org>/<repository>
WARNING WARNING
return
end end
end end