diff --git a/Library/Homebrew/livecheck/strategy/gnome.rb b/Library/Homebrew/livecheck/strategy/gnome.rb index ea2a468155..e30e61372f 100644 --- a/Library/Homebrew/livecheck/strategy/gnome.rb +++ b/Library/Homebrew/livecheck/strategy/gnome.rb @@ -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/(?.*?)/}i =~ url + %r{/sources/(?[^/]+)/}i =~ url page_url = "https://download.gnome.org/sources/#{package_name}/cache.json" diff --git a/Library/Homebrew/livecheck/strategy/hackage.rb b/Library/Homebrew/livecheck/strategy/hackage.rb index 0796762c6d..04cfddcee2 100644 --- a/Library/Homebrew/livecheck/strategy/hackage.rb +++ b/Library/Homebrew/livecheck/strategy/hackage.rb @@ -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. # diff --git a/Library/Homebrew/livecheck/strategy/npm.rb b/Library/Homebrew/livecheck/strategy/npm.rb index 7a21653d0f..a1342b63e5 100644 --- a/Library/Homebrew/livecheck/strategy/npm.rb +++ b/Library/Homebrew/livecheck/strategy/npm.rb @@ -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/(?.+)/-/}i =~ url + %r{registry\.npmjs\.org/(?(?:[^/]+/)?[^/]+)/-/}i =~ url page_url = "https://www.npmjs.com/package/#{package_name}?activeTab=versions" diff --git a/Library/Homebrew/livecheck/strategy/pypi.rb b/Library/Homebrew/livecheck/strategy/pypi.rb index 2b588a165f..ba03c41a6d 100644 --- a/Library/Homebrew/livecheck/strategy/pypi.rb +++ b/Library/Homebrew/livecheck/strategy/pypi.rb @@ -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. # diff --git a/Library/Homebrew/test/livecheck/strategy/hackage_spec.rb b/Library/Homebrew/test/livecheck/strategy/hackage_spec.rb index 11a35d7ba5..7a393294a7 100644 --- a/Library/Homebrew/test/livecheck/strategy/hackage_spec.rb +++ b/Library/Homebrew/test/livecheck/strategy/hackage_spec.rb @@ -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 diff --git a/Library/Homebrew/test/livecheck/strategy/npm_spec.rb b/Library/Homebrew/test/livecheck/strategy/npm_spec.rb index 2612434283..2ed3280633 100644 --- a/Library/Homebrew/test/livecheck/strategy/npm_spec.rb +++ b/Library/Homebrew/test/livecheck/strategy/npm_spec.rb @@ -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