File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
Sources/ContainerRegistry
Tests/ContainerRegistryTests Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,7 @@ extension ImageReference {
116116 public enum ValidationError : Error , Equatable {
117117 case emptyString
118118 case containsUppercaseLetters( String )
119+ case invalidReferenceFormat( String )
119120 }
120121
121122 public init ( _ rawValue: String ) throws {
@@ -129,6 +130,12 @@ extension ImageReference {
129130 throw ValidationError . containsUppercaseLetters ( rawValue)
130131 }
131132
133+ // https://github.com/opencontainers/distribution-spec/blob/main/spec.md#pulling-manifests
134+ let regex = /[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*(\/ [ a- z0- 9 ] + ( ( \.| _|__|-+ ) [ a- z0- 9 ] + ) * ) * /
135+ if try regex. wholeMatch ( in: rawValue) == nil {
136+ throw ValidationError . invalidReferenceFormat ( rawValue)
137+ }
138+
132139 value = rawValue
133140 }
134141
Original file line number Diff line number Diff line change @@ -188,6 +188,10 @@ struct ReferenceTests {
188188 #expect( throws: ImageReference . Repository. ValidationError. containsUppercaseLetters ( " helloWorld " ) ) {
189189 try ImageReference ( fromString: " localhost:5555/helloWorld " )
190190 }
191+
192+ #expect( throws: ImageReference . Repository. ValidationError. invalidReferenceFormat ( " hello^world " ) ) {
193+ try ImageReference ( fromString: " localhost:5555/hello^world " )
194+ }
191195 }
192196
193197 @Test
You can’t perform that action at this time.
0 commit comments