Skip to content

Commit

Permalink
Merge pull request #16728 from reitermarkus/tap-from-path-regex
Browse files Browse the repository at this point in the history
Fix tap constants.
  • Loading branch information
reitermarkus authored Feb 22, 2024
2 parents d3ef383 + ed07203 commit 94e987e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Library/Homebrew/tap_constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
HOMEBREW_TAP_FORMULA_NAME_REGEX = T.let(/(?<name>[\w+\-.@]+)/, Regexp)
# Match taps' formulae, e.g. `someuser/sometap/someformula`.
HOMEBREW_TAP_FORMULA_REGEX = T.let(
%r{\A(?<user>[\w-]+)/(?<repo>[\w-]+)/#{HOMEBREW_TAP_FORMULA_NAME_REGEX.source}\Z},
%r{\A(?<user>[^/]+)/(?<repo>[^/]+)/#{HOMEBREW_TAP_FORMULA_NAME_REGEX.source}\Z},
Regexp,
)
# Match default formula taps' formulae, e.g. `homebrew/core/someformula` or `someformula`.
Expand All @@ -18,7 +18,7 @@
HOMEBREW_TAP_CASK_TOKEN_REGEX = T.let(/(?<token>[a-z0-9\-_]+(?:@[a-z0-9\-_.]+)?)/, Regexp)
# Match taps' casks, e.g. `someuser/sometap/somecask`.
HOMEBREW_TAP_CASK_REGEX = T.let(
%r{\A(?<user>[\w-]+)/(?<repo>[\w-]+)/#{HOMEBREW_TAP_CASK_TOKEN_REGEX.source}\Z},
%r{\A(?<user>[^/]+)/(?<repo>[^/]+)/#{HOMEBREW_TAP_CASK_TOKEN_REGEX.source}\Z},
Regexp,
)
# Match default cask taps' casks, e.g. `homebrew/cask/somecask` or `somecask`.
Expand All @@ -29,14 +29,19 @@

# Match taps' directory paths, e.g. `HOMEBREW_LIBRARY/Taps/someuser/sometap`.
HOMEBREW_TAP_DIR_REGEX = T.let(
%r{#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Taps/(?<user>[\w-]+)/(?<repo>[\w-]+)},
%r{#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Taps/(?<user>[^/]+)/(?<repo>[^/]+)},
Regexp,
)
# Match taps' formula paths, e.g. `HOMEBREW_LIBRARY/Taps/someuser/sometap/someformula`.
HOMEBREW_TAP_PATH_REGEX = T.let(Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + %r{(?:/.*)?\Z}.source).freeze, Regexp)
# Match official taps' casks, e.g. `homebrew/cask/somecask or homebrew/cask-versions/somecask`.
# Match official cask taps, e.g `homebrew/cask`.
HOMEBREW_CASK_TAP_REGEX = T.let(
%r{(?:([Cc]askroom)/(cask|versions)|([Hh]omebrew)/(?:homebrew-)?(cask|cask-[\w-]+))},
Regexp,
)
# Match official taps' casks, e.g. `homebrew/cask/somecask` or `homebrew/cask-versions/somecask`.
HOMEBREW_CASK_TAP_CASK_REGEX = T.let(
%r{\A(?:([Cc]askroom)/(cask|versions)|([Hh]omebrew)/(?:homebrew-)?(cask|cask-[\w-]+))/([\w+-.]+)\Z},
%r{\A#{HOMEBREW_CASK_TAP_REGEX.source}/#{HOMEBREW_TAP_CASK_TOKEN_REGEX.source}\Z},
Regexp,
)
HOMEBREW_OFFICIAL_REPO_PREFIXES_REGEX = T.let(/\A(home|linux)brew-/, Regexp)
12 changes: 12 additions & 0 deletions Library/Homebrew/test/tap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ def setup_completion(link:)
it "returns the Tap when given its exact path" do
expect(described_class.from_path(path)).to eq tap
end

context "when path contains a dot" do
let(:tap) { described_class.fetch("str4d.xyz", "rage") }

after do
tap.uninstall
end

it "returns the Tap when given its exact path" do
expect(described_class.from_path(path)).to eq tap
end
end
end

specify "::names" do
Expand Down

0 comments on commit 94e987e

Please sign in to comment.