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 @@ -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}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments