Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit invalid versions #15936

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@

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 @@
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, ".")

Check warning on line 129 in Library/Homebrew/github_packages.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/github_packages.rb#L129

Added line #L129 was not covered by tests
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