From 0fe3bf7c7fe2ad76fdf803ed7f2d8353f1a98795 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 14 Dec 2020 02:09:23 +0100 Subject: [PATCH] Only use `Sparkle` strategy if URL is specified explicitly. --- Library/Homebrew/livecheck/livecheck.rb | 8 +++++--- Library/Homebrew/livecheck/strategy.rb | 8 ++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 8af477178a..f29c62144c 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -435,9 +435,9 @@ module Homebrew has_livecheckable = formula_or_cask.livecheckable? livecheck = formula_or_cask.livecheck + livecheck_url = livecheck.url livecheck_regex = livecheck.regex livecheck_strategy = livecheck.strategy - livecheck_url = livecheck.url urls = [livecheck_url] if livecheck_url.present? urls ||= checkable_urls(formula_or_cask) @@ -475,7 +475,9 @@ module Homebrew strategies = Strategy.from_url( url, livecheck_strategy: livecheck_strategy, + url_provided: livecheck_url.present?, regex_provided: livecheck_regex.present?, + block_provided: livecheck.strategy_block.present?, ) strategy = Strategy.from_symbol(livecheck_strategy) strategy ||= strategies.first @@ -490,8 +492,8 @@ module Homebrew puts "Regex: #{livecheck_regex.inspect}" if livecheck_regex.present? end - if livecheck_strategy == :page_match && livecheck_regex.blank? - odebug "#{strategy_name} strategy requires a regex" + if livecheck_strategy == :page_match && (livecheck_regex.blank? && livecheck.strategy_block.blank?) + odebug "#{strategy_name} strategy requires a regex or block" next end diff --git a/Library/Homebrew/livecheck/strategy.rb b/Library/Homebrew/livecheck/strategy.rb index 6a566ad16b..fecfc44a08 100644 --- a/Library/Homebrew/livecheck/strategy.rb +++ b/Library/Homebrew/livecheck/strategy.rb @@ -57,12 +57,16 @@ module Homebrew # @param regex_provided [Boolean] whether a regex is provided in the # `livecheck` block # @return [Array] - def from_url(url, livecheck_strategy: nil, regex_provided: nil) + def from_url(url, livecheck_strategy: nil, url_provided: nil, regex_provided: nil, block_provided: nil) usable_strategies = strategies.values.select do |strategy| if strategy == PageMatch # Only treat the `PageMatch` strategy as usable if a regex is # present in the `livecheck` block - next unless regex_provided + next unless (regex_provided || block_provided) + elsif strategy == Sparkle && (livecheck_strategy || !url_provided) + # Skip the `Sparkle` strategy if a strategy is specified explicitly + # or if the URL is not specified explicitly. + next elsif strategy.const_defined?(:PRIORITY) && !strategy::PRIORITY.positive? && from_symbol(livecheck_strategy) != strategy