diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index 7039f72ac8..1c668c98b7 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -790,7 +790,7 @@ module Homebrew tag = SharedAudits.gitlab_tag_from_url(url) tag ||= stable.specs[:tag] - tag ||= stable.version + tag ||= stable.version.to_s if @online error = SharedAudits.gitlab_release(owner, repo, tag, formula:) diff --git a/Library/Homebrew/test/utils/shared_audits_spec.rb b/Library/Homebrew/test/utils/shared_audits_spec.rb new file mode 100644 index 0000000000..819536c355 --- /dev/null +++ b/Library/Homebrew/test/utils/shared_audits_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require "utils/shared_audits" + +RSpec.describe SharedAudits do + describe "::gitlab_tag_from_url" do + it "doesn't find tags in invalid urls" do + url = "https://gitlab.com/a/-/archive/v1.2.3/a-v1.2.3.tar.gz" + expect(described_class.gitlab_tag_from_url(url)).to be_nil + end + + it "finds tags in basic urls" do + url = "https://gitlab.com/a/b/-/archive/v1.2.3/b-1.2.3.tar.gz" + expect(described_class.gitlab_tag_from_url(url)).to eq("v1.2.3") + end + + it "finds tags in urls with subgroups" do + url = "https://gitlab.com/a/b/c/d/e/f/g/-/archive/2.5/g-2.5.tar.gz" + expect(described_class.gitlab_tag_from_url(url)).to eq("2.5") + end + + it "finds tags in urls with special characters" do + url = "https://gitlab.com/a.b/c-d_e/-/archive/2.5/c-d_e-2.5.tar.gz" + expect(described_class.gitlab_tag_from_url(url)).to eq("2.5") + end + end +end diff --git a/Library/Homebrew/utils/shared_audits.rb b/Library/Homebrew/utils/shared_audits.rb index f6a4b9b420..ff11c429eb 100644 --- a/Library/Homebrew/utils/shared_audits.rb +++ b/Library/Homebrew/utils/shared_audits.rb @@ -197,9 +197,6 @@ module SharedAudits sig { params(url: String).returns(T.nilable(String)) } def self.gitlab_tag_from_url(url) - url = url.to_s - url.match(%r{^https://gitlab\.com/[\w-]+/[\w-]+/-/archive/([^/]+)/}) - .to_a - .second + url[%r{^https://gitlab\.com/(?:\w[\w.-]*/){2,}-/archive/([^/]+)/}, 1] end end