From e709917cd596de5c6bc3eeec271d2e8bb1ff5764 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Tue, 19 Oct 2021 10:01:39 -0400 Subject: [PATCH] Apache: Extend URL_MATCH_REGEX Some Apache URLs use a `filename` query string parameter instead of `path` and the `Apache` strategy isn't applied. The parameter value is the same as `path` (i.e., a path to a file), so this updates the strategy's `URL_MATCH_REGEX` to handle this URL format as well. --- Library/Homebrew/livecheck/strategy/apache.rb | 9 ++++--- .../test/livecheck/strategy/apache_spec.rb | 25 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy/apache.rb b/Library/Homebrew/livecheck/strategy/apache.rb index 37ce2ce3c7..f9987cfab4 100644 --- a/Library/Homebrew/livecheck/strategy/apache.rb +++ b/Library/Homebrew/livecheck/strategy/apache.rb @@ -7,14 +7,15 @@ module Homebrew # The {Apache} strategy identifies versions of software at apache.org # by checking directory listing pages. # - # Apache URLs start with `https://www.apache.org/dyn/closer.lua?path=`. - # The `path` parameter takes one of the following formats: + # Apache URLs start with `https://www.apache.org/dyn/` and include + # a `filename` or `path` query string parameter where the value is a + # path to a file. The path takes one of the following formats: # # * `example/1.2.3/example-1.2.3.tar.gz` # * `example/example-1.2.3/example-1.2.3.tar.gz` # * `example/example-1.2.3-bin.tar.gz` # - # When the `path` contains a version directory (e.g. `/1.2.3/`, + # When the path contains a version directory (e.g. `/1.2.3/`, # `/example-1.2.3/`, etc.), the default regex matches numeric versions # in directory names. Otherwise, the default regex matches numeric # versions in filenames. @@ -26,7 +27,7 @@ module Homebrew # The `Regexp` used to determine if the strategy applies to the URL. URL_MATCH_REGEX = %r{ ^https?://www\.apache\.org - /dyn/.+path= + /dyn/.+(?:path|filename)= (?.+?)/ # Path to directory of files or version directories (?[^/]*?) # Any text in filename or directory before version v?\d+(?:\.\d+)+ # The numeric version diff --git a/Library/Homebrew/test/livecheck/strategy/apache_spec.rb b/Library/Homebrew/test/livecheck/strategy/apache_spec.rb index c2e2391b6e..fdbf02aa04 100644 --- a/Library/Homebrew/test/livecheck/strategy/apache_spec.rb +++ b/Library/Homebrew/test/livecheck/strategy/apache_spec.rb @@ -7,11 +7,23 @@ describe Homebrew::Livecheck::Strategy::Apache do subject(:apache) { described_class } let(:apache_urls) { - { + urls = { version_dir: "https://www.apache.org/dyn/closer.lua?path=abc/1.2.3/def-1.2.3.tar.gz", name_and_version_dir: "https://www.apache.org/dyn/closer.lua?path=abc/def-1.2.3/ghi-1.2.3.tar.gz", name_dir_bin: "https://www.apache.org/dyn/closer.lua?path=abc/def/ghi-1.2.3-bin.tar.gz", } + + # Add mirrors.cgi test URLs using the same paths + urls.clone.each do |key, url| + next unless url.include?("/closer.lua?path=") + + urls["mirrors_#{key}".to_sym] = url.sub( + "/closer.lua?path=", + "/mirrors/mirrors.cgi?action=download&filename=", + ) + end + + urls } let(:non_apache_url) { "https://brew.sh/test" } @@ -34,9 +46,7 @@ describe Homebrew::Livecheck::Strategy::Apache do describe "::match?" do it "returns true for an Apache URL" do - expect(apache.match?(apache_urls[:version_dir])).to be true - expect(apache.match?(apache_urls[:name_and_version_dir])).to be true - expect(apache.match?(apache_urls[:name_dir_bin])).to be true + apache_urls.each_value { |url| expect(apache.match?(url)).to be true } end it "returns false for a non-Apache URL" do @@ -46,9 +56,10 @@ describe Homebrew::Livecheck::Strategy::Apache do describe "::generate_input_values" do it "returns a hash containing url and regex for an Apache URL" do - expect(apache.generate_input_values(apache_urls[:version_dir])).to eq(generated[:version_dir]) - expect(apache.generate_input_values(apache_urls[:name_and_version_dir])).to eq(generated[:name_and_version_dir]) - expect(apache.generate_input_values(apache_urls[:name_dir_bin])).to eq(generated[:name_dir_bin]) + apache_urls.each do |key, url| + generated_key = key.to_s.start_with?("mirrors_") ? key.to_s.delete_prefix("mirrors_").to_sym : key + expect(apache.generate_input_values(url)).to eq(generated[generated_key]) + end end it "returns an empty hash for a non-Apache URL" do