Skip to content

Commit 95b5848

Browse files
committed
Allow repo name ending in wildcard "*".
1 parent 0abdd8f commit 95b5848

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

metadata.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ func SaveImageMetadata(metadataSlice []ImageMetadataInfo) {
10911091
}
10921092

10931093
// 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.
10941095
func ValidRepoName(name string) bool {
10951096
if len(name) == 0 {
10961097
return false
@@ -1099,7 +1100,7 @@ func ValidRepoName(name string) bool {
10991100
blog.Error("Invalid repo name, too long: %s", name)
11001101
return false
11011102
}
1102-
for _, c := range name {
1103+
for i, c := range name {
11031104
switch {
11041105
case c >= 'a' && c <= 'z':
11051106
continue
@@ -1109,6 +1110,8 @@ func ValidRepoName(name string) bool {
11091110
continue
11101111
case c == '/' || c == '_' || c == '-' || c == '.':
11111112
continue
1113+
case c == '*' && i == len(name)-1:
1114+
continue
11121115
default:
11131116
blog.Error("Invalid repo name %s", name)
11141117
return false

metadata_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestGetLocalImageMetadata(t *testing.T) {
2828
ReposToProcess[RepoType(metadata.Repo)] = true
2929
currentMetadataSlice = GetLocalImageMetadata(MetadataSet)
3030

31-
for _, localImage := range(currentMetadataSlice) {
31+
for _, localImage := range currentMetadataSlice {
3232
fmt.Println("localImage: ", localImage)
3333
if localImage.Repo == metadata.Repo && localImage.Tag == metadata.Tag {
3434
fmt.Println("TestGetLocalImageMetadata succeeded for ", metadata)
@@ -38,3 +38,18 @@ func TestGetLocalImageMetadata(t *testing.T) {
3838
t.Fatal("TestGetLocalImageMetadata failed for ", metadata)
3939
return
4040
}
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+
}

0 commit comments

Comments
 (0)