Skip to content

Commit 06f9a71

Browse files
committed
ContainerRegistry: Reject capital letters in repository names
1 parent a30ce30 commit 06f9a71

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Sources/ContainerRegistry/ImageReference.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ extension ImageReference {
113113
public struct Repository: Sendable, Equatable, CustomStringConvertible, CustomDebugStringConvertible {
114114
var value: String
115115

116-
public enum ValidationError: Error {
116+
public enum ValidationError: Error, Equatable {
117117
case emptyString
118+
case containsUppercaseLetters(String)
118119
}
119120

120121
public init(_ rawValue: String) throws {
@@ -124,6 +125,10 @@ extension ImageReference {
124125
throw ValidationError.emptyString
125126
}
126127

128+
if (rawValue.contains { $0.isUppercase }) {
129+
throw ValidationError.containsUppercaseLetters(rawValue)
130+
}
131+
127132
value = rawValue
128133
}
129134

Tests/ContainerRegistryTests/ImageReferenceTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ struct ReferenceTests {
170170
#expect(throws: ImageReference.Repository.ValidationError.emptyString) {
171171
try ImageReference(fromString: "example.com/")
172172
}
173+
174+
#expect(throws: ImageReference.Repository.ValidationError.containsUppercaseLetters("helloWorld")) {
175+
try ImageReference(fromString: "helloWorld", defaultRegistry: "default")
176+
}
177+
178+
#expect(throws: ImageReference.Repository.ValidationError.containsUppercaseLetters("helloWorld")) {
179+
try ImageReference(fromString: "localhost:5555/helloWorld")
180+
}
173181
}
174182

175183
@Test

0 commit comments

Comments
 (0)