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.
This commit is contained in:
parent
bfe9693083
commit
e709917cd5
@ -7,14 +7,15 @@ module Homebrew
|
|||||||
# The {Apache} strategy identifies versions of software at apache.org
|
# The {Apache} strategy identifies versions of software at apache.org
|
||||||
# by checking directory listing pages.
|
# by checking directory listing pages.
|
||||||
#
|
#
|
||||||
# Apache URLs start with `https://www.apache.org/dyn/closer.lua?path=`.
|
# Apache URLs start with `https://www.apache.org/dyn/` and include
|
||||||
# The `path` parameter takes one of the following formats:
|
# 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/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/example-1.2.3.tar.gz`
|
||||||
# * `example/example-1.2.3-bin.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
|
# `/example-1.2.3/`, etc.), the default regex matches numeric versions
|
||||||
# in directory names. Otherwise, the default regex matches numeric
|
# in directory names. Otherwise, the default regex matches numeric
|
||||||
# versions in filenames.
|
# versions in filenames.
|
||||||
@ -26,7 +27,7 @@ module Homebrew
|
|||||||
# The `Regexp` used to determine if the strategy applies to the URL.
|
# The `Regexp` used to determine if the strategy applies to the URL.
|
||||||
URL_MATCH_REGEX = %r{
|
URL_MATCH_REGEX = %r{
|
||||||
^https?://www\.apache\.org
|
^https?://www\.apache\.org
|
||||||
/dyn/.+path=
|
/dyn/.+(?:path|filename)=
|
||||||
(?<path>.+?)/ # Path to directory of files or version directories
|
(?<path>.+?)/ # Path to directory of files or version directories
|
||||||
(?<prefix>[^/]*?) # Any text in filename or directory before version
|
(?<prefix>[^/]*?) # Any text in filename or directory before version
|
||||||
v?\d+(?:\.\d+)+ # The numeric version
|
v?\d+(?:\.\d+)+ # The numeric version
|
||||||
|
@ -7,11 +7,23 @@ describe Homebrew::Livecheck::Strategy::Apache do
|
|||||||
subject(:apache) { described_class }
|
subject(:apache) { described_class }
|
||||||
|
|
||||||
let(:apache_urls) {
|
let(:apache_urls) {
|
||||||
{
|
urls = {
|
||||||
version_dir: "https://www.apache.org/dyn/closer.lua?path=abc/1.2.3/def-1.2.3.tar.gz",
|
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_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",
|
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" }
|
let(:non_apache_url) { "https://brew.sh/test" }
|
||||||
|
|
||||||
@ -34,9 +46,7 @@ describe Homebrew::Livecheck::Strategy::Apache do
|
|||||||
|
|
||||||
describe "::match?" do
|
describe "::match?" do
|
||||||
it "returns true for an Apache URL" do
|
it "returns true for an Apache URL" do
|
||||||
expect(apache.match?(apache_urls[:version_dir])).to be true
|
apache_urls.each_value { |url| expect(apache.match?(url)).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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false for a non-Apache URL" do
|
it "returns false for a non-Apache URL" do
|
||||||
@ -46,9 +56,10 @@ describe Homebrew::Livecheck::Strategy::Apache do
|
|||||||
|
|
||||||
describe "::generate_input_values" do
|
describe "::generate_input_values" do
|
||||||
it "returns a hash containing url and regex for an Apache URL" 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])
|
apache_urls.each do |key, url|
|
||||||
expect(apache.generate_input_values(apache_urls[:name_and_version_dir])).to eq(generated[:name_and_version_dir])
|
generated_key = key.to_s.start_with?("mirrors_") ? key.to_s.delete_prefix("mirrors_").to_sym : key
|
||||||
expect(apache.generate_input_values(apache_urls[:name_dir_bin])).to eq(generated[:name_dir_bin])
|
expect(apache.generate_input_values(url)).to eq(generated[generated_key])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an empty hash for a non-Apache URL" do
|
it "returns an empty hash for a non-Apache URL" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user