From 4abcfdb7c68e8d74413f09e7fdd5b1ba391d37e3 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 14 Dec 2020 09:25:31 +0100 Subject: [PATCH 1/4] Use more exact regex as `URL_MATCH_REGEX` for `Bitbucket` strategy. --- .../Homebrew/livecheck/strategy/bitbucket.rb | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy/bitbucket.rb b/Library/Homebrew/livecheck/strategy/bitbucket.rb index e37690ba6dffb..c3e0007f1dc42 100644 --- a/Library/Homebrew/livecheck/strategy/bitbucket.rb +++ b/Library/Homebrew/livecheck/strategy/bitbucket.rb @@ -29,7 +29,14 @@ module Strategy # @api public class Bitbucket # The `Regexp` used to determine if the strategy applies to the URL. - URL_MATCH_REGEX = %r{bitbucket\.org(/[^/]+){4}\.\w+}i.freeze + URL_MATCH_REGEX = %r{ + bitbucket\.org/ + (?.+?)/ # The path leading up to the get or downloads part + (?get|downloads)/ # An indicator of the file download type + (?(?:[^/]+?[_-])?) # Filename text before the version + v?\d+(?:\.\d+)+ # The numeric version + (?[^/]+) # Filename text after the version + }ix.freeze # Whether the strategy can be applied to the provided URL. # @@ -46,30 +53,23 @@ def self.match?(url) # @param regex [Regexp] a regex used for matching versions in content # @return [Hash] def self.find_versions(url, regex = nil) - %r{ - bitbucket\.org/ - (?.+?)/ # The path leading up to the get or downloads part - (?get|downloads)/ # An indicator of the file download type - (?(?:[^/]+?[_-])?) # Filename text before the version - v?\d+(?:\.\d+)+ # The numeric version - (?[^/]+) # Filename text after the version - }ix =~ url + match = url.match(URL_MATCH_REGEX) # Use `\.t` instead of specific tarball extensions (e.g. .tar.gz) - suffix.sub!(/\.t(?:ar\..+|[a-z0-9]+)$/i, "\.t") + match[:suffix].sub!(/\.t(?:ar\..+|[a-z0-9]+)$/i, "\.t") # `/get/` archives are Git tag snapshots, so we need to check that tab # instead of the main `/downloads/` page - page_url = if dl_type == "get" - "https://bitbucket.org/#{path}/downloads/?tab=tags" + page_url = if match[:dl_type] == "get" + "https://bitbucket.org/#{match[:path]}/downloads/?tab=tags" else - "https://bitbucket.org/#{path}/downloads/" + "https://bitbucket.org/#{match[:path]}/downloads/" end # Example regexes: # * `/href=.*?v?(\d+(?:\.\d+)+)\.t/i` # * `/href=.*?example-v?(\d+(?:\.\d+)+)\.t/i` - regex ||= /href=.*?#{Regexp.escape(prefix)}v?(\d+(?:\.\d+)+)#{Regexp.escape(suffix)}/i + regex ||= /href=.*?#{Regexp.escape(match[:prefix])}v?(\d+(?:\.\d+)+)#{Regexp.escape(match[:suffix])}/i Homebrew::Livecheck::Strategy::PageMatch.find_versions(page_url, regex) end From cbbc932c21cce3451fb3f80a3d00b4f18908a976 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 19 Dec 2020 19:55:57 +0100 Subject: [PATCH 2/4] Don't replace string inside of `MatchData`. --- Library/Homebrew/livecheck/strategy/bitbucket.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy/bitbucket.rb b/Library/Homebrew/livecheck/strategy/bitbucket.rb index c3e0007f1dc42..8066183e3d6d3 100644 --- a/Library/Homebrew/livecheck/strategy/bitbucket.rb +++ b/Library/Homebrew/livecheck/strategy/bitbucket.rb @@ -56,7 +56,7 @@ def self.find_versions(url, regex = nil) match = url.match(URL_MATCH_REGEX) # Use `\.t` instead of specific tarball extensions (e.g. .tar.gz) - match[:suffix].sub!(/\.t(?:ar\..+|[a-z0-9]+)$/i, "\.t") + suffix = match[:suffix].sub(/\.t(?:ar\..+|[a-z0-9]+)$/i, "\.t") # `/get/` archives are Git tag snapshots, so we need to check that tab # instead of the main `/downloads/` page @@ -69,7 +69,7 @@ def self.find_versions(url, regex = nil) # Example regexes: # * `/href=.*?v?(\d+(?:\.\d+)+)\.t/i` # * `/href=.*?example-v?(\d+(?:\.\d+)+)\.t/i` - regex ||= /href=.*?#{Regexp.escape(match[:prefix])}v?(\d+(?:\.\d+)+)#{Regexp.escape(match[:suffix])}/i + regex ||= /href=.*?#{Regexp.escape(match[:prefix])}v?(\d+(?:\.\d+)+)#{Regexp.escape(suffix)}/i Homebrew::Livecheck::Strategy::PageMatch.find_versions(page_url, regex) end From 21b188838836b9c1b950c222894af783980ce1d6 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sun, 20 Dec 2020 16:00:08 -0500 Subject: [PATCH 3/4] Bitbucket: Anchor start of regex with protocol --- Library/Homebrew/livecheck/strategy/bitbucket.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/livecheck/strategy/bitbucket.rb b/Library/Homebrew/livecheck/strategy/bitbucket.rb index 8066183e3d6d3..b28ce5e98920d 100644 --- a/Library/Homebrew/livecheck/strategy/bitbucket.rb +++ b/Library/Homebrew/livecheck/strategy/bitbucket.rb @@ -30,7 +30,7 @@ module Strategy class Bitbucket # The `Regexp` used to determine if the strategy applies to the URL. URL_MATCH_REGEX = %r{ - bitbucket\.org/ + ^https?://bitbucket\.org/ (?.+?)/ # The path leading up to the get or downloads part (?get|downloads)/ # An indicator of the file download type (?(?:[^/]+?[_-])?) # Filename text before the version From 466e55c6ab121e5f0008707e4cefff2bac0e8fca Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sun, 20 Dec 2020 18:13:51 -0500 Subject: [PATCH 4/4] Bitbucket: Format regex like other strategies --- Library/Homebrew/livecheck/strategy/bitbucket.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy/bitbucket.rb b/Library/Homebrew/livecheck/strategy/bitbucket.rb index b28ce5e98920d..48d20a7860ac3 100644 --- a/Library/Homebrew/livecheck/strategy/bitbucket.rb +++ b/Library/Homebrew/livecheck/strategy/bitbucket.rb @@ -30,10 +30,10 @@ module Strategy class Bitbucket # The `Regexp` used to determine if the strategy applies to the URL. URL_MATCH_REGEX = %r{ - ^https?://bitbucket\.org/ - (?.+?)/ # The path leading up to the get or downloads part - (?get|downloads)/ # An indicator of the file download type - (?(?:[^/]+?[_-])?) # Filename text before the version + ^https?://bitbucket\.org + /(?.+?) # The path leading up to the get or downloads part + /(?get|downloads) # An indicator of the file download type + /(?(?:[^/]+?[_-])?) # Filename text before the version v?\d+(?:\.\d+)+ # The numeric version (?[^/]+) # Filename text after the version }ix.freeze