@@ -66,7 +66,7 @@ def self.parse_docker_uri(docker_uri)
6666 end
6767
6868 path = 'library/' + path if ( official_docker_registry ( name_parts [ 0 ] ) || missing_registry ( name_parts ) ) && path . exclude? ( '/' )
69- path , tag_digest = parse_docker_tag_or_digest_from_path ( path )
69+ path , tag_digest = parse_docker_tag_digest_from_path ( path )
7070
7171 raise InvalidDockerURI . new "Invalid image name [#{ path } ]" unless DOCKER_PATH_REGEX =~ path
7272 raise InvalidDockerURI . new "Invalid image tag [#{ tag_digest } ]" if tag_digest && !( DOCKER_TAG_DIGEST_REGEX =~ tag_digest )
@@ -92,10 +92,30 @@ def self.parse_docker_uri(docker_uri)
9292 ( host . exclude? ( '.' ) && host . exclude? ( ':' ) && host != 'localhost' )
9393 end
9494
95- private_class_method def self . parse_docker_tag_or_digest_from_path ( path )
96- path , tag_digest = path . split ( /@|:/ , 2 )
97- return [ path , tag_digest ] unless tag_digest && tag_digest . include? ( '/' )
95+ private_class_method def self . parse_docker_tag_digest_from_path ( path )
96+ # Split path into base path and digest if digest is present (after '@')
97+ base_path , digest = path . split ( '@' , 2 )
98+
99+ if digest
100+ # If digest is present and base_path contains a tag (':'), split it
101+ if base_path . include? ( ':' )
102+ base_path , tag = base_path . split ( ':' , 2 )
103+ # Return path and combined tag@digest
104+ return [ base_path , "#{ tag } @#{ digest } " ]
105+ end
106+
107+ # Return path and digest if no tag present
108+ return [ base_path , digest ]
109+ end
110+
111+ # No digest present, check for tag
112+ base_path , tag = base_path . split ( ':' , 2 )
113+
114+ # If tag is present but looks like a path segment (contains '/'), treat as no tag
115+ return [ base_path , 'latest' ] if tag &.include? ( '/' )
116+
117+ # Return path and tag (or nil if no tag)
118+ [ base_path , tag ]
98119
99- [ path , 'latest' ]
100120 end
101121end
0 commit comments