Skip to content

Commit 52f68cf

Browse files
committed
ContainerRegistry: Reject other invalid characters in repository names
1 parent eda6d95 commit 52f68cf

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Sources/ContainerRegistry/ImageReference.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ extension ImageReference {
124124
throw RepositoryParseError.containsUppercaseLetters(rawValue)
125125
}
126126

127+
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md#pulling-manifests
128+
let regex = /[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*(\/[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*)*/
129+
if try regex.wholeMatch(in: rawValue) == nil {
130+
throw RepositoryParseError.invalidReferenceFormat(rawValue)
131+
}
132+
127133
value = rawValue
128134
}
129135

@@ -140,5 +146,6 @@ extension ImageReference {
140146
public enum RepositoryParseError: Error, Equatable {
141147
case emptyString
142148
case containsUppercaseLetters(String)
149+
case invalidReferenceFormat(String)
143150
}
144151
}

Tests/ContainerRegistryTests/ImageReferenceTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ struct ReferenceTests {
146146
#expect(throws: ImageReference.RepositoryParseError.containsUppercaseLetters("helloWorld")) {
147147
try ImageReference(fromString: "localhost:5555/helloWorld")
148148
}
149+
150+
#expect(throws: ImageReference.RepositoryParseError.invalidReferenceFormat("hello^world")) {
151+
try ImageReference(fromString: "localhost:5555/hello^world")
152+
}
149153
}
150154

151155
@Test

0 commit comments

Comments
 (0)