Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli/named_args: better handle name conflicts in #to_paths #16069

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions Library/Homebrew/cli/named_args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ def to_resolved_formulae_to_casks(only: parent&.only_formula_or_cask)
to_formulae_to_casks(only: only, method: :resolve)
end

LOCAL_PATH_REGEX = %r{^/|[.]|/$}.freeze
TAP_NAME_REGEX = %r{^[^./]+/[^./]+$}.freeze
private_constant :LOCAL_PATH_REGEX, :TAP_NAME_REGEX

# Keep existing paths and try to convert others to tap, formula or cask paths.
# If a cask and formula with the same name exist, includes both their paths
# unless `only` is specified.
Expand All @@ -230,9 +234,9 @@ def to_paths(only: parent&.only_formula_or_cask, recurse_tap: false)
@to_paths[only] ||= Homebrew.with_no_api_env_if_needed(@without_api) do
downcased_unique_named.flat_map do |name|
path = Pathname(name).expand_path
if only.nil? && File.exist?(name)
if only.nil? && name.match?(LOCAL_PATH_REGEX) && path.exist?
path
elsif name.count("/") == 1 && !name.start_with?("./", "/")
elsif name.match?(TAP_NAME_REGEX)
tap = Tap.fetch(name)

if recurse_tap
Expand Down