From 59308809202492c0a0d5d54fc4c69451471548ae Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Fri, 10 Jun 2022 19:07:05 -0400 Subject: [PATCH] Gnome: Update default regex and version filtering The `Gnome` strategy's default regex uses the `+` form of the standard regex for matching versions like 1.2.3. However, with the switch to the new version scheme, some packages had a release that omits a minor and patch (i.e., `40` instead of `40.0`). The default regex fails to match versions like this but the looser `*` form will match both. [When creating regexes, we generally start with the `+` form and only switch to the looser `*` form when it's necessary and contextually-appropriate.] This also updates the default version filtering logic that's applied to versions using the old GNOME version scheme (below version 40). Outside of the refactoring changes, this also filters out versions where the patch number is 90+, as these are also unstable. --- Library/Homebrew/livecheck/strategy/gnome.rb | 8 ++++++-- Library/Homebrew/test/livecheck/strategy/gnome_spec.rb | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy/gnome.rb b/Library/Homebrew/livecheck/strategy/gnome.rb index 49baed77c6..ecf11c7d25 100644 --- a/Library/Homebrew/livecheck/strategy/gnome.rb +++ b/Library/Homebrew/livecheck/strategy/gnome.rb @@ -66,7 +66,7 @@ module Homebrew # GNOME archive files seem to use a standard filename format, so we # count on the delimiter between the package name and numeric # version being a hyphen and the file being a tarball. - values[:regex] = /#{regex_name}-(\d+(?:\.\d+)+)\.t/i + values[:regex] = /#{regex_name}-(\d+(?:\.\d+)*)\.t/i values end @@ -99,7 +99,11 @@ module Homebrew # Filter out unstable versions using the old version scheme where # the major version is below 40. version_data[:matches].reject! do |_, version| - version.major < 40 && (version.minor >= 90 || version.minor.to_i.odd?) + next if version.major >= 40 + next if version.minor.blank? + + (version.minor.to_i.odd? || version.minor >= 90) || + (version.patch.present? && version.patch >= 90) end end diff --git a/Library/Homebrew/test/livecheck/strategy/gnome_spec.rb b/Library/Homebrew/test/livecheck/strategy/gnome_spec.rb index 03d33dd4f7..6da013d92d 100644 --- a/Library/Homebrew/test/livecheck/strategy/gnome_spec.rb +++ b/Library/Homebrew/test/livecheck/strategy/gnome_spec.rb @@ -12,7 +12,7 @@ describe Homebrew::Livecheck::Strategy::Gnome do let(:generated) { { url: "https://download.gnome.org/sources/abc/cache.json", - regex: /abc-(\d+(?:\.\d+)+)\.t/i, + regex: /abc-(\d+(?:\.\d+)*)\.t/i, } }