Skip to content

Commit

Permalink
Merge branch '3.0.x' into 3.1.x
Browse files Browse the repository at this point in the history
Closes gh-37183
  • Loading branch information
wilkinsona committed Sep 4, 2023
2 parents 03dcf8b + d6b04af commit c562e8e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.boot.buildpack.platform.docker.type;

import java.io.File;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -260,14 +261,23 @@ public static ImageReference of(String value) {
path = path.substring(0, tagSplit) + remainder;
}
}
Assert.isTrue(Regex.PATH.matcher(path).matches(),

Assert.isTrue(isLowerCase(path) && matchesPathRegex(path),
() -> "Unable to parse image reference \"" + value + "\". "
+ "Image reference must be in the form '[domainHost:port/][path/]name[:tag][@digest]', "
+ "with 'path' and 'name' containing only [a-z0-9][.][_][-]");
ImageName name = new ImageName(domain, path);
return new ImageReference(name, tag, digest);
}

private static boolean isLowerCase(String path) {
return path.toLowerCase(Locale.ENGLISH).equals(path);
}

private static boolean matchesPathRegex(String path) {
return Regex.PATH.matcher(path).matches();
}

/**
* Create a new {@link ImageReference} from the given {@link ImageName}.
* @param name the image name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ void ofWhenHasIllegalCharacter() {
.withMessageContaining("Unable to parse image reference");
}

@Test
void ofWhenContainsUpperCaseThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ImageReference
.of("europe-west1-docker.pkg.dev/aaaaaa-bbbbb-123456/docker-registry/bootBuildImage:0.0.1"))
.withMessageContaining("Unable to parse image reference");
}

@Test
void forJarFile() {
assertForJarFile("spring-boot.2.0.0.BUILD-SNAPSHOT.jar", "library/spring-boot", "2.0.0.BUILD-SNAPSHOT");
Expand Down

0 comments on commit c562e8e

Please sign in to comment.