Skip to content

platforms: add Validate utility for OCI platform specifications - #39

Draft
thaJeztah wants to merge 2 commits into
containerd:mainfrom
thaJeztah:add_validate
Draft

thaJeztah wants to merge 2 commits into
containerd:mainfrom
thaJeztah:add_validate

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

platforms: add Validate utility for OCI platform specifications

Add Validate to check that a platform has non-empty OS and
architecture fields and that its components are well-formed.

Validation follows the existing platform specifier syntax, rejecting
invalid characters and path components such as "." and "..", without
restricting values to known or supported platforms.

This allows callers to validate platform specifications without
formatting, parsing, or normalizing them.

Reject "." and ".." as architecture or variant components when parsing
platform specifiers.

These values were previously accepted, but are treated as path components
by path.Join, which is used by Format and FormatAll. This could cause
platforms to be silently changed when formatting them, making parsing
and formatting inconsistent.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Add Validate to check that a platform has non-empty OS and
architecture fields and that its components are well-formed.

Validation follows the existing platform specifier syntax, rejecting
invalid characters and path components such as "." and "..", without
restricting values to known or supported platforms.

This allows callers to validate platform specifications without
formatting, parsing, or normalizing them.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Comment thread platforms.go
return fmt.Errorf(`%q must not be "." or "..": %w`, s, errInvalidArgument)
}
if !specifierRe.MatchString(s) {
return fmt.Errorf("platform specifier component must match %q: %w", specifierRe.String(), errInvalidArgument)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this error also include s?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should the other not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants