From ba7cf9df7a022f37d6806e7257e6ccdc0b142dc8 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Fri, 19 May 2023 10:51:49 -0400 Subject: [PATCH] Bitbucket: Fix tag match The `Bitbucket` strategy currently matches versions from tag tarball links on a project's `downloads/?tab=tags` page. It appears that Bitbucket now uses a hash as the filename on this page instead of the tag name, so the existing regex no longer matches. This adds an alternative regex to match versions from the tag name element (e.g., `example-1.2.3`), which will fix version matching in this scenario. --- .../Homebrew/livecheck/strategy/bitbucket.rb | 35 +++++++++++-------- .../test/livecheck/strategy/bitbucket_spec.rb | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy/bitbucket.rb b/Library/Homebrew/livecheck/strategy/bitbucket.rb index dd319ca6e2..822b6fe4b9 100644 --- a/Library/Homebrew/livecheck/strategy/bitbucket.rb +++ b/Library/Homebrew/livecheck/strategy/bitbucket.rb @@ -61,24 +61,29 @@ module Homebrew match = url.match(URL_MATCH_REGEX) return values if match.blank? - # `/get/` archives are Git tag snapshots, so we need to check that tab - # instead of the main `/downloads/` page - values[:url] = if match[:dl_type] == "get" - "https://bitbucket.org/#{match[:path]}/downloads/?tab=tags" - else - "https://bitbucket.org/#{match[:path]}/downloads/" - end - regex_prefix = Regexp.escape(T.must(match[:prefix])).gsub("\\-", "-") - # Use `\.t` instead of specific tarball extensions (e.g. .tar.gz) - suffix = T.must(match[:suffix]).sub(Strategy::TARBALL_EXTENSION_REGEX, ".t") - regex_suffix = Regexp.escape(suffix).gsub("\\-", "-") + # `/get/` archives are Git tag snapshots, so we need to check that tab + # instead of the main `/downloads/` page + if match[:dl_type] == "get" + values[:url] = "https://bitbucket.org/#{match[:path]}/downloads/?tab=tags" - # Example regexes: - # * `/href=.*?v?(\d+(?:\.\d+)+)\.t/i` - # * `/href=.*?example-v?(\d+(?:\.\d+)+)\.t/i` - values[:regex] = /href=.*?#{regex_prefix}v?(\d+(?:\.\d+)+)#{regex_suffix}/i + # Example tag regexes: + # * `/]*?class="name"[^>]*?>\s*v?(\d+(?:\.\d+)+)\s*?]*?class="name"[^>]*?>\s*abc-v?(\d+(?:\.\d+)+)\s*?]*?class="name"[^>]*?>\s*#{regex_prefix}v?(\d+(?:\.\d+)+)\s*?]*?class="name"[^>]*?>\s*v?(\d+(?:\.\d+)+)\s*?