diff --git a/Library/Homebrew/livecheck/strategy.rb b/Library/Homebrew/livecheck/strategy.rb index 61e7e06ed3..0d4c6c022c 100644 --- a/Library/Homebrew/livecheck/strategy.rb +++ b/Library/Homebrew/livecheck/strategy.rb @@ -151,25 +151,25 @@ module Homebrew ).returns(T::Array[T.untyped]) } def from_url(url, livecheck_strategy: nil, url_provided: false, regex_provided: false, block_provided: false) - usable_strategies = strategies.values.select do |strategy| + usable_strategies = strategies.select do |strategy_symbol, strategy| if strategy == PageMatch # Only treat the strategy as usable if the `livecheck` block # contains a regex and/or `strategy` block next if !regex_provided && !block_provided elsif strategy == Json # Only treat the strategy as usable if the `livecheck` block - # contains a `strategy` block - next unless block_provided + # specifies the strategy and contains a `strategy` block + next if (livecheck_strategy != strategy_symbol) || !block_provided elsif strategy.const_defined?(:PRIORITY) && !strategy::PRIORITY.positive? && - from_symbol(livecheck_strategy) != strategy + livecheck_strategy != strategy_symbol # Ignore strategies with a priority of 0 or lower, unless the # strategy is specified in the `livecheck` block next end strategy.respond_to?(:match?) && strategy.match?(url) - end + end.values # Sort usable strategies in descending order by priority, using the # DEFAULT_PRIORITY when a strategy doesn't contain a PRIORITY constant