From 28451bd2bc88c8cedc3b0cd0dcec657c739c7e0e Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:29:10 -0500 Subject: [PATCH] Use Sparkle sorting/filtering in #livecheck_min_os The `#livecheck_min_os` cask audit method manually replicates some of the `Sparkle` strategy's behavior but in an incomplete way that has lead to inappropriate audit failures at times. This reimplements it to use `Livecheck` methods, so it will align with the `Sparkle` strategy's behavior. --- Library/Homebrew/cask/audit.rb | 38 ++++++++++++++-------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 51b07e781b..1cc4433c19 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -603,31 +603,25 @@ module Cask return if cask.livecheck.strategy_block.present? && cask.livecheck.strategy_block.parameters[0] == [:opt, :items] - out, _, status = curl_output("--fail", "--silent", "--location", cask.livecheck.url) - return unless status.success? - - require "rexml/document" - - xml = begin - REXML::Document.new(out) - rescue REXML::ParseException - nil - end - - return if xml.blank? - - item = xml.elements["//rss//channel//item"] - return if item.blank? - - min_os = item.elements["sparkle:minimumSystemVersion"]&.text - min_os = "11" if min_os == "10.16" - return if min_os.blank? + content = Homebrew::Livecheck::Strategy.page_content(cask.livecheck.url)[:content] + return if content.blank? begin - MacOSVersion.new(min_os).strip_patch - rescue MacOSVersion::Error - nil + items = Homebrew::Livecheck::Strategy::Sparkle.sort_items( + Homebrew::Livecheck::Strategy::Sparkle.filter_items( + Homebrew::Livecheck::Strategy::Sparkle.items_from_content(content), + ), + ) + rescue + return end + return if items.blank? + + min_os = items[0]&.minimum_system_version&.strip_patch + # Big Sur is sometimes identified as 10.16, so we override it to the + # expected macOS version (11). + min_os = MacOSVersion.new("11") if min_os == "10.16" + min_os end sig { returns(T.nilable(MacOSVersion)) }