mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Speed up ImageReference.of when path contains upper-case chars
Closes gh-35657
This commit is contained in:
parent
49cf62d97c
commit
fadc58679d
@ -17,6 +17,7 @@
|
|||||||
package org.springframework.boot.buildpack.platform.docker.type;
|
package org.springframework.boot.buildpack.platform.docker.type;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -260,7 +261,8 @@ public final class ImageReference {
|
|||||||
path = path.substring(0, tagSplit) + remainder;
|
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 + "\". "
|
() -> "Unable to parse image reference \"" + value + "\". "
|
||||||
+ "Image reference must be in the form '[domainHost:port/][path/]name[:tag][@digest]', "
|
+ "Image reference must be in the form '[domainHost:port/][path/]name[:tag][@digest]', "
|
||||||
+ "with 'path' and 'name' containing only [a-z0-9][.][_][-]");
|
+ "with 'path' and 'name' containing only [a-z0-9][.][_][-]");
|
||||||
@ -268,6 +270,14 @@ public final class ImageReference {
|
|||||||
return new ImageReference(name, tag, digest);
|
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}.
|
* Create a new {@link ImageReference} from the given {@link ImageName}.
|
||||||
* @param name the image name
|
* @param name the image name
|
||||||
|
@ -180,6 +180,14 @@ class ImageReferenceTests {
|
|||||||
.withMessageContaining("Unable to parse image reference");
|
.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
|
@Test
|
||||||
void forJarFile() {
|
void forJarFile() {
|
||||||
assertForJarFile("spring-boot.2.0.0.BUILD-SNAPSHOT.jar", "library/spring-boot", "2.0.0.BUILD-SNAPSHOT");
|
assertForJarFile("spring-boot.2.0.0.BUILD-SNAPSHOT.jar", "library/spring-boot", "2.0.0.BUILD-SNAPSHOT");
|
||||||
|
Loading…
Reference in New Issue
Block a user