@@ -18,6 +18,9 @@ import (
18
18
var (
19
19
GitCommitRegex = regexp .MustCompile (`^[0-9a-f]{1,64}$` )
20
20
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}$` )
21
24
)
22
25
23
26
type Manifest2822 struct {
@@ -395,6 +398,9 @@ func (manifest *Manifest2822) AddEntry(entry Manifest2822Entry) error {
395
398
entry .DeduplicateSharedTags ()
396
399
entry .CleanDirectoryValues ()
397
400
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
+ }
398
404
if invalidArchitectures := entry .InvalidArchitectures (); len (invalidArchitectures ) > 0 {
399
405
return fmt .Errorf ("Tags %q has invalid Architectures: %q" , entry .TagsString (), strings .Join (invalidArchitectures , ", " ))
400
406
}
@@ -458,6 +464,16 @@ func (entry Manifest2822Entry) InvalidMaintainers() []string {
458
464
return invalid
459
465
}
460
466
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
+
461
477
func (entry Manifest2822Entry ) InvalidArchitectures () []string {
462
478
invalid := []string {}
463
479
for _ , arch := range entry .Architectures {
0 commit comments