aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorJosh Hagins2016-10-24 10:38:02 -0400
committerGitHub2016-10-24 10:38:02 -0400
commit3f3fa4d0f7d5c28598fb7a2495d01efa35c7f7a2 (patch)
tree9c5c67ecb24d00c8911700dc0ab43ef434bd4a56 /Library/Homebrew
parentb481ed73a079ea6abecf18529d61eea87e85d058 (diff)
parentb2870c2480744aa7d202c4975e3169b05035f7ed (diff)
downloadbrew-3f3fa4d0f7d5c28598fb7a2495d01efa35c7f7a2.tar.bz2
Merge pull request #1334 from jawshooah/cask/fix-tap-regex
hbc/qualified_token: simplify token parsing
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/cask/lib/hbc/qualified_token.rb34
-rw-r--r--Library/Homebrew/cmd/install.rb2
-rw-r--r--Library/Homebrew/extend/ARGV.rb2
-rw-r--r--Library/Homebrew/tap_constants.rb4
4 files changed, 8 insertions, 34 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/qualified_token.rb b/Library/Homebrew/cask/lib/hbc/qualified_token.rb
index 8868bd65d..09eedef1b 100644
--- a/Library/Homebrew/cask/lib/hbc/qualified_token.rb
+++ b/Library/Homebrew/cask/lib/hbc/qualified_token.rb
@@ -1,37 +1,9 @@
module Hbc
module QualifiedToken
- REPO_PREFIX = "homebrew-".freeze
-
- # per https://github.com/Homebrew/homebrew/blob/4c7bc9ec3bca729c898ee347b6135ba692ee0274/Library/Homebrew/cmd/tap.rb#L121
- USER_REGEX = /[a-z0-9_\-]+/
-
- # per https://github.com/Homebrew/homebrew/blob/4c7bc9ec3bca729c898ee347b6135ba692ee0274/Library/Homebrew/cmd/tap.rb#L121
- REPO_REGEX = /(?:#{REPO_PREFIX})?\w+/
-
- # per https://github.com/caskroom/homebrew-cask/blob/master/CONTRIBUTING.md#generating-a-token-for-the-cask
- TOKEN_REGEX = /[a-z0-9\-]+/
-
- TAP_REGEX = %r{#{USER_REGEX}[/\-]#{REPO_REGEX}}
-
- QUALIFIED_TOKEN_REGEX = %r{#{TAP_REGEX}/#{TOKEN_REGEX}}
-
def self.parse(arg)
- return nil unless arg.is_a?(String) && arg.downcase =~ /^#{QUALIFIED_TOKEN_REGEX}$/
- path_elements = arg.downcase.split("/")
- if path_elements.count == 2
- # eg phinze-cask/google-chrome.
- # Not certain this form is needed, but it was supported in the past.
- token = path_elements[1]
- dash_elements = path_elements[0].split("-")
- repo = dash_elements.pop
- dash_elements.pop if dash_elements.count > 1 && dash_elements[-1] + "-" == REPO_PREFIX
- user = dash_elements.join("-")
- else
- # eg caskroom/cask/google-chrome
- # per https://github.com/Homebrew/brew/blob/master/docs/brew-tap.md
- user, repo, token = path_elements
- end
- repo.sub!(/^#{REPO_PREFIX}/, "")
+ return nil unless arg.is_a?(String)
+ return nil unless match = arg.downcase.match(HOMEBREW_TAP_CASK_REGEX)
+ user, repo, token = match.captures
odebug "[user, repo, token] might be [#{user}, #{repo}, #{token}]"
[user, repo, token]
end
diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb
index 2c027a52e..0867e893a 100644
--- a/Library/Homebrew/cmd/install.rb
+++ b/Library/Homebrew/cmd/install.rb
@@ -76,7 +76,7 @@ module Homebrew
unless ARGV.force?
ARGV.named.each do |name|
next if File.exist?(name)
- if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_FORMULA_REGEX
+ if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_CASK_REGEX
next
end
tap = Tap.fetch($1, $2)
diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb
index f2f959f22..0adf8d548 100644
--- a/Library/Homebrew/extend/ARGV.rb
+++ b/Library/Homebrew/extend/ARGV.rb
@@ -58,7 +58,7 @@ module HomebrewArgvExtension
end
def casks
- @casks ||= downcased_unique_named.grep HOMEBREW_CASK_TAP_FORMULA_REGEX
+ @casks ||= downcased_unique_named.grep HOMEBREW_CASK_TAP_CASK_REGEX
end
def kegs
diff --git a/Library/Homebrew/tap_constants.rb b/Library/Homebrew/tap_constants.rb
index 12de02f49..4ef8015c2 100644
--- a/Library/Homebrew/tap_constants.rb
+++ b/Library/Homebrew/tap_constants.rb
@@ -1,8 +1,10 @@
# match taps' formulae, e.g. someuser/sometap/someformula
HOMEBREW_TAP_FORMULA_REGEX = %r{^([\w-]+)/([\w-]+)/([\w+-.@]+)$}
+# match taps' casks, e.g. someuser/sometap/somecask
+HOMEBREW_TAP_CASK_REGEX = %r{^([\w-]+)/([\w-]+)/([a-z0-9\-]+)$}
# match taps' directory paths, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap
HOMEBREW_TAP_DIR_REGEX = %r{#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Taps/([\w-]+)/([\w-]+)}
# match taps' formula paths, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap/someformula
HOMEBREW_TAP_PATH_REGEX = Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + %r{/(.*)}.source)
# match the default and the versions brew-cask tap e.g. Caskroom/cask or Caskroom/versions
-HOMEBREW_CASK_TAP_FORMULA_REGEX = %r{^([Cc]askroom)/(cask|versions)/([\w+-.]+)$}
+HOMEBREW_CASK_TAP_CASK_REGEX = %r{^([Cc]askroom)/(cask|versions)/([\w+-.]+)$}