Skip to content

Commit

Permalink
Merge pull request #41533 from MikeEdgar/fix-image-registry-npe
Browse files Browse the repository at this point in the history
Avoid NPE handling registry in image reference parsing
  • Loading branch information
geoand authored Jul 3, 2024
2 parents 7b817b5 + 9be28f5 commit db472de
Showing 1 changed file with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,29 @@ public static ImageReference parse(String reference) {
String tag = matcher.group(3);
String digest = matcher.group(4);

// If no registry was matched, use Docker Hub by default.
if (StringUtil.isNullOrEmpty(registry)) {
registry = null;
}

if (StringUtil.isNullOrEmpty(repository)) {
throw new IllegalArgumentException("Reference " + reference + " is invalid: The repository was not set");
}
/*
* If a registry was matched but it does not contain any dots or colons, it should actually be
* part of the repository unless it is "localhost".
*
* See https://github.com/docker/distribution/blob/245ca4659e09e9745f3cc1217bf56e946509220c/reference/normalize.go#L62
*/
if (!registry.contains(".") && !registry.contains(":") && !"localhost".equals(registry)) {

if (StringUtil.isNullOrEmpty(registry)) {
registry = null;
} else if (!registry.contains(".") && !registry.contains(":") && !"localhost".equals(registry)) {
/*
* If a registry was matched but it does not contain any dots or colons, it should actually be
* part of the repository unless it is "localhost".
*
* See
* https://github.com/docker/distribution/blob/245ca4659e09e9745f3cc1217bf56e946509220c/reference/normalize.go#L62
*/
repository = registry + "/" + repository;
registry = null;
}

/*
* For Docker Hub, if the repository is only one component, then it should be prefixed with
* 'library/'.
*
* See https://docs.docker.com/engine/reference/commandline/pull/#pull-an-image-from-docker-hub
*/
if (DOCKER_HUB_REGISTRY.equals(registry) && repository.indexOf('/') < 0) {
} else if (DOCKER_HUB_REGISTRY.equals(registry) && repository.indexOf('/') < 0) {
/*
* For Docker Hub, if the repository is only one component, then it should be prefixed with
* 'library/'.
*
* See https://docs.docker.com/engine/reference/commandline/pull/#pull-an-image-from-docker-hub
*/
repository = LIBRARY_REPOSITORY_PREFIX + repository;
}

Expand Down

0 comments on commit db472de

Please sign in to comment.