livecheck: strengthen URL patterns

This commit is contained in:
Dario Vladovic 2020-12-12 01:31:41 +01:00 committed by Sam Ford
parent a7b61c645a
commit 86fee106a3
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE
6 changed files with 10 additions and 6 deletions

View File

@ -20,7 +20,7 @@ module Homebrew
NICE_NAME = "GNOME"
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = /download\.gnome\.org/i.freeze
URL_MATCH_REGEX = %r{^https?://download\.gnome\.org/sources/[^/]+/}i.freeze
# Whether the strategy can be applied to the provided URL.
#
@ -37,7 +37,7 @@ module Homebrew
# @param regex [Regexp] a regex used for matching versions in content
# @return [Hash]
def self.find_versions(url, regex = nil, &block)
%r{/sources/(?<package_name>.*?)/}i =~ url
%r{/sources/(?<package_name>[^/]+)/}i =~ url
page_url = "https://download.gnome.org/sources/#{package_name}/cache.json"

View File

@ -18,7 +18,7 @@ module Homebrew
# @api public
class Hackage
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = /(?:downloads|hackage)\.haskell\.org/i.freeze
URL_MATCH_REGEX = %r{^https?://(?:downloads|hackage)\.haskell\.org(?:/[^/]+){3}}i.freeze
# Whether the strategy can be applied to the provided URL.
#

View File

@ -20,7 +20,7 @@ module Homebrew
NICE_NAME = "npm"
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = /registry\.npmjs\.org/i.freeze
URL_MATCH_REGEX = %r{^https?://registry\.npmjs\.org(?:/[^/]+)?/[^/]+/-/}i.freeze
# Whether the strategy can be applied to the provided URL.
#
@ -37,7 +37,7 @@ module Homebrew
# @param regex [Regexp] a regex used for matching versions in content
# @return [Hash]
def self.find_versions(url, regex = nil, &block)
%r{registry\.npmjs\.org/(?<package_name>.+)/-/}i =~ url
%r{registry\.npmjs\.org/(?<package_name>(?:[^/]+/)?[^/]+)/-/}i =~ url
page_url = "https://www.npmjs.com/package/#{package_name}?activeTab=versions"

View File

@ -20,7 +20,7 @@ module Homebrew
NICE_NAME = "PyPI"
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = /files\.pythonhosted\.org/i.freeze
URL_MATCH_REGEX = %r{^https?://files\.pythonhosted\.org/packages(?:/[^/]+){4}i}.freeze
# Whether the strategy can be applied to the provided URL.
#

View File

@ -7,11 +7,13 @@ describe Homebrew::Livecheck::Strategy::Hackage do
subject(:hackage) { described_class }
let(:hackage_url) { "https://hackage.haskell.org/package/abc-1.2.3/def-1.2.3.tar.gz" }
let(:hackage_downloads_url) { "https://downloads.haskell.org/~abc/1.2.3/def-1.2.3-src.tar.xz" }
let(:non_hackage_url) { "https://brew.sh/test" }
describe "::match?" do
it "returns true if the argument provided is a Hackage URL" do
expect(hackage.match?(hackage_url)).to be true
expect(hackage.match?(hackage_downloads_url)).to be true
end
it "returns false if the argument provided is not a Hackage URL" do

View File

@ -7,11 +7,13 @@ describe Homebrew::Livecheck::Strategy::Npm do
subject(:npm) { described_class }
let(:npm_url) { "https://registry.npmjs.org/abc/-/def-1.2.3.tgz" }
let(:npm_scoped_url) { "https://registry.npmjs.org/@example/abc/-/def-1.2.3.tgz" }
let(:non_npm_url) { "https://brew.sh/test" }
describe "::match?" do
it "returns true if the argument provided is an npm URL" do
expect(npm.match?(npm_url)).to be true
expect(npm.match?(npm_scoped_url)).to be true
end
it "returns false if the argument provided is not an npm URL" do