Skip to content

Commit

Permalink
Merge pull request #15936 from MikeMcQuaid/audit_invalid_versions
Browse files Browse the repository at this point in the history
Audit invalid versions
  • Loading branch information
MikeMcQuaid committed Sep 5, 2023
2 parents 5ffe524 + de4207f commit 9677a9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Library/Homebrew/github_packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class GitHubPackages

URL_REGEX = %r{(?:#{Regexp.escape(URL_PREFIX)}|#{Regexp.escape(DOCKER_PREFIX)})([\w-]+)/([\w-]+)}.freeze

# Valid OCI tag characters
# https://github.com/opencontainers/distribution-spec/blob/main/spec.md#workflow-categories
VALID_OCI_TAG_REGEX = /^[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127}$/.freeze
INVALID_OCI_TAG_CHARS_REGEX = /[^a-zA-Z0-9._-]/.freeze

GZIP_BUFFER_SIZE = 64 * 1024
private_constant :GZIP_BUFFER_SIZE

Expand Down Expand Up @@ -117,10 +122,11 @@ def self.image_formula_name(formula_name)
end

def self.image_version_rebuild(version_rebuild)
# invalid docker tag characters
# TODO: consider changing the actual versions here and make an audit to
# avoid these weird characters being used
version_rebuild.gsub(/[+#~]/, ".")
return version_rebuild if version_rebuild.match?(VALID_OCI_TAG_REGEX)

# odeprecated "GitHub Packages versions that do not match #{VALID_OCI_TAG_REGEX.source}",
# "declaring a new `version` without these characters"
version_rebuild.gsub(INVALID_OCI_TAG_CHARS_REGEX, ".")
end

private
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/resource_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def audit
def audit_version
if version.nil?
problem "missing version"
elsif owner.is_a?(Formula) && !version.to_s.match?(GitHubPackages::VALID_OCI_TAG_REGEX)
problem "version #{version} does not match #{GitHubPackages::VALID_OCI_TAG_REGEX.source}"
elsif !version.detected_from_url?
version_text = version
version_url = Version.detect(url, **specs)
Expand Down

0 comments on commit 9677a9a

Please sign in to comment.