From 38ae98cbcd2690142506aa86b34a769175e53c41 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Fri, 20 May 2022 01:43:00 +0100 Subject: [PATCH] livecheck: improve host checks to instead check domains --- Library/Homebrew/livecheck/livecheck.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 1f03af6e96..b63a211417 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -492,34 +492,35 @@ module Homebrew sig { params(url: String).returns(String) } def preprocess_url(url) begin - uri = URI.parse url - rescue URI::InvalidURIError + uri = Addressable::URI.parse url + rescue Addressable::URI::InvalidURIError return url end host = uri.host + domain = uri.domain path = uri.path return url if host.nil? || path.nil? - host = "github.com" if host == "github.s3.amazonaws.com" + domain = host = "github.com" if host == "github.s3.amazonaws.com" path = path.delete_prefix("/").delete_suffix(".git") scheme = uri.scheme - if host.end_with?("github.com") + if domain == "github.com" return url if path.match? %r{/releases/latest/?$} owner, repo = path.delete_prefix("downloads/").split("/") url = "#{scheme}://#{host}/#{owner}/#{repo}.git" - elsif host.end_with?(*GITEA_INSTANCES) + elsif GITEA_INSTANCES.include?(domain) return url if path.match? %r{/releases/latest/?$} owner, repo = path.split("/") url = "#{scheme}://#{host}/#{owner}/#{repo}.git" - elsif host.end_with?(*GOGS_INSTANCES) + elsif GOGS_INSTANCES.include?(domain) owner, repo = path.split("/") url = "#{scheme}://#{host}/#{owner}/#{repo}.git" # sourcehut - elsif host.end_with?("git.sr.ht") + elsif host == "git.sr.ht" owner, repo = path.split("/") url = "#{scheme}://#{host}/#{owner}/#{repo}" # GitLab (gitlab.com or self-hosted)