Skip to content

Commit eda6d95

Browse files
committed
ContainerRegistry: Reject capital letters in repository names
1 parent 327636f commit eda6d95

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Sources/ContainerRegistry/ImageReference.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ func splitName(_ name: String) throws -> (String, String) {
4545
return (String(tagSplit[0]), String(tagSplit[1]))
4646
}
4747

48-
/// Repository refers a repository (image namespace) on a container registry
49-
5048
/// ImageReference points to an image stored on a container registry
5149
public struct ImageReference: Sendable, Equatable, CustomStringConvertible, CustomDebugStringConvertible {
5250
/// The registry which contains this image
@@ -111,6 +109,7 @@ public struct ImageReference: Sendable, Equatable, CustomStringConvertible, Cust
111109
}
112110

113111
extension ImageReference {
112+
/// Repository refers a repository (image namespace) on a container registry
114113
public struct Repository: Sendable, Equatable, CustomStringConvertible, CustomDebugStringConvertible {
115114
var value: String
116115

@@ -121,6 +120,10 @@ extension ImageReference {
121120
throw RepositoryParseError.emptyString
122121
}
123122

123+
if (rawValue.contains { $0.isUppercase }) {
124+
throw RepositoryParseError.containsUppercaseLetters(rawValue)
125+
}
126+
124127
value = rawValue
125128
}
126129

@@ -134,7 +137,8 @@ extension ImageReference {
134137
}
135138
}
136139

137-
public enum RepositoryParseError: Error {
140+
public enum RepositoryParseError: Error, Equatable {
138141
case emptyString
142+
case containsUppercaseLetters(String)
139143
}
140144
}

Tests/ContainerRegistryTests/ImageReferenceTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,18 @@ struct ReferenceTests {
134134
#expect(throws: ImageReference.RepositoryParseError.emptyString) {
135135
try ImageReference(fromString: "", defaultRegistry: "default")
136136
}
137+
138+
#expect(throws: ImageReference.RepositoryParseError.emptyString) {
139+
try ImageReference(fromString: "example.com/")
140+
}
141+
142+
#expect(throws: ImageReference.RepositoryParseError.containsUppercaseLetters("helloWorld")) {
143+
try ImageReference(fromString: "helloWorld", defaultRegistry: "default")
144+
}
145+
146+
#expect(throws: ImageReference.RepositoryParseError.containsUppercaseLetters("helloWorld")) {
147+
try ImageReference(fromString: "localhost:5555/helloWorld")
148+
}
137149
}
138150

139151
@Test

0 commit comments

Comments
 (0)