Strategy#from_url: Amend conditions for Json
When the `Json` strategy was introduced, I forgot to also ensure that it's only treated as usable (in `Strategy#from_url`) if a `livecheck` block uses `strategy :json`. As a result, `Json` is incorrectly treated as a usable strategy for all formulae/casks that contain a `strategy` block. Since all of these `livecheck` blocks specify a strategy, this bug doesn't meaningfully impact livecheck's behavior (i.e., these checks continue to use their explicitly-specified strategy). The only practical difference is that `Json` incorrectly appears in the list of usable strategies in livecheck's verbose JSON output. This commit modifies `Strategy#from_url` to address this issue. The easiest way to enforce this rule involved passing in the `@strategies` key (a symbol) into the `select` block, so we can compare it to `livecheck_strategy` (the strategy symbol specified in the `livecheck` block).
This commit is contained in:
parent
86aeac6857
commit
03823b5698
@ -151,15 +151,15 @@ 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
|
||||
@ -169,7 +169,7 @@ module Homebrew
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user