Skip to content
This repository was archived by the owner on Aug 22, 2020. It is now read-only.

Commit 3ff8c5c

Browse files
committed
Add "(Shared)Tags" validation
1 parent c37ef75 commit 3ff8c5c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

manifest/rfc2822.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import (
1818
var (
1919
GitCommitRegex = regexp.MustCompile(`^[0-9a-f]{1,64}$`)
2020
GitFetchRegex = regexp.MustCompile(`^refs/(heads|tags)/[^*?:]+$`)
21+
22+
// https://github.com/docker/distribution/blob/v2.7.1/reference/regexp.go#L37
23+
ValidTagRegex = regexp.MustCompile(`^\w[\w.-]{0,127}$`)
2124
)
2225

2326
type Manifest2822 struct {
@@ -395,6 +398,9 @@ func (manifest *Manifest2822) AddEntry(entry Manifest2822Entry) error {
395398
entry.DeduplicateSharedTags()
396399
entry.CleanDirectoryValues()
397400

401+
if invalidTags := entry.InvalidTags(); len(invalidTags) > 0 {
402+
return fmt.Errorf("Tags %q has invalid (Shared)Tags: %q", entry.TagsString(), strings.Join(invalidTags, ", "))
403+
}
398404
if invalidArchitectures := entry.InvalidArchitectures(); len(invalidArchitectures) > 0 {
399405
return fmt.Errorf("Tags %q has invalid Architectures: %q", entry.TagsString(), strings.Join(invalidArchitectures, ", "))
400406
}
@@ -458,6 +464,16 @@ func (entry Manifest2822Entry) InvalidMaintainers() []string {
458464
return invalid
459465
}
460466

467+
func (entry Manifest2822Entry) InvalidTags() []string {
468+
invalid := []string{}
469+
for _, tag := range append(append([]string{}, entry.Tags...), entry.SharedTags...) {
470+
if !ValidTagRegex.MatchString(tag) {
471+
invalid = append(invalid, tag)
472+
}
473+
}
474+
return invalid
475+
}
476+
461477
func (entry Manifest2822Entry) InvalidArchitectures() []string {
462478
invalid := []string{}
463479
for _, arch := range entry.Architectures {

0 commit comments

Comments
 (0)