File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -1091,6 +1091,7 @@ func SaveImageMetadata(metadataSlice []ImageMetadataInfo) {
1091
1091
}
1092
1092
1093
1093
// ValidRepoName verifies that the name of a repo is in a legal format.
1094
+ // A valid name can optionally include a wildcard "*" but only as the last character.
1094
1095
func ValidRepoName (name string ) bool {
1095
1096
if len (name ) == 0 {
1096
1097
return false
@@ -1099,7 +1100,7 @@ func ValidRepoName(name string) bool {
1099
1100
blog .Error ("Invalid repo name, too long: %s" , name )
1100
1101
return false
1101
1102
}
1102
- for _ , c := range name {
1103
+ for i , c := range name {
1103
1104
switch {
1104
1105
case c >= 'a' && c <= 'z' :
1105
1106
continue
@@ -1109,6 +1110,8 @@ func ValidRepoName(name string) bool {
1109
1110
continue
1110
1111
case c == '/' || c == '_' || c == '-' || c == '.' :
1111
1112
continue
1113
+ case c == '*' && i == len (name )- 1 :
1114
+ continue
1112
1115
default :
1113
1116
blog .Error ("Invalid repo name %s" , name )
1114
1117
return false
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ func TestGetLocalImageMetadata(t *testing.T) {
28
28
ReposToProcess [RepoType (metadata .Repo )] = true
29
29
currentMetadataSlice = GetLocalImageMetadata (MetadataSet )
30
30
31
- for _ , localImage := range ( currentMetadataSlice ) {
31
+ for _ , localImage := range currentMetadataSlice {
32
32
fmt .Println ("localImage: " , localImage )
33
33
if localImage .Repo == metadata .Repo && localImage .Tag == metadata .Tag {
34
34
fmt .Println ("TestGetLocalImageMetadata succeeded for " , metadata )
@@ -38,3 +38,18 @@ func TestGetLocalImageMetadata(t *testing.T) {
38
38
t .Fatal ("TestGetLocalImageMetadata failed for " , metadata )
39
39
return
40
40
}
41
+
42
+ func TestValidRepoName (t * testing.T ) {
43
+ testCases := map [string ]bool {
44
+ "library/ubuntu" : true ,
45
+ "abc/def/ghi" : true ,
46
+ "q:x&2" : false ,
47
+ "banyan/*" : true ,
48
+ "foo*bar/xyz" : false ,
49
+ }
50
+ for repo , expected := range testCases {
51
+ if ValidRepoName (repo ) != expected {
52
+ t .Fatalf ("TestValidRepoName ValidRepoName(%s) did not return %v" , repo , expected )
53
+ }
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments