Skip to content

Commit bb384f2

Browse files
Merge branch '3.2.x'
Closes gh-39639
2 parents 806a39e + 71e5e12 commit bb384f2

File tree

4 files changed

+47
-7
lines changed
  • spring-boot-project
    • spring-boot-docker-compose/src
    • spring-boot-tools/spring-boot-buildpack-platform/src

4 files changed

+47
-7
lines changed

spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/Regex.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ final class Regex implements CharSequence {
5050
private static final Regex PATH_COMPONENT;
5151
static {
5252
Regex segment = Regex.of("[a-z0-9]+");
53-
Regex separator = Regex.group("[._]|__|[-]*");
53+
Regex separator = Regex.group("[._-]{1,2}");
5454
Regex separatedSegment = Regex.group(separator, segment).oneOrMoreTimes();
5555
PATH_COMPONENT = Regex.of(segment, Regex.group(separatedSegment).zeroOrOnce());
5656
}

spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/ImageReferenceTests.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,8 @@
1717
package org.springframework.boot.docker.compose.core;
1818

1919
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.Timeout;
21+
import org.junit.jupiter.api.Timeout.ThreadMode;
2022

2123
import static org.assertj.core.api.Assertions.assertThat;
2224
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -39,6 +41,16 @@ void ofSimpleName() {
3941
assertThat(reference).hasToString("docker.io/library/ubuntu");
4042
}
4143

44+
@Test
45+
void ofSimpleNameWithSingleCharacterSuffix() {
46+
ImageReference reference = ImageReference.of("ubuntu-a");
47+
assertThat(reference.getDomain()).isEqualTo("docker.io");
48+
assertThat(reference.getName()).isEqualTo("library/ubuntu-a");
49+
assertThat(reference.getTag()).isNull();
50+
assertThat(reference.getDigest()).isNull();
51+
assertThat(reference).hasToString("docker.io/library/ubuntu-a");
52+
}
53+
4254
@Test
4355
void ofLibrarySlashName() {
4456
ImageReference reference = ImageReference.of("library/ubuntu");
@@ -149,13 +161,21 @@ void ofCustomDomainAndPortWithTag() {
149161
}
150162

151163
@Test
152-
void ofWhenHasIllegalCharacter() {
164+
void ofWhenHasIllegalCharacterThrowsException() {
153165
assertThatIllegalArgumentException()
154166
.isThrownBy(() -> ImageReference
155167
.of("registry.example.com/example/example-app:1.6.0-dev.2.uncommitted+wip.foo.c75795d"))
156168
.withMessageContaining("Unable to parse image reference");
157169
}
158170

171+
@Test
172+
@Timeout(value = 1, threadMode = ThreadMode.SEPARATE_THREAD)
173+
void ofWhenImageNameIsVeryLongAndHasIllegalCharacterThrowsException() {
174+
assertThatIllegalArgumentException().isThrownBy(() -> ImageReference
175+
.of("docker.io/library/this-image-has-a-long-name-with-an-invalid-tag-which-is-at-danger-of-catastrophic-backtracking:1.0.0+1234"))
176+
.withMessageContaining("Unable to parse image reference");
177+
}
178+
159179
@Test
160180
void equalsAndHashCode() {
161181
ImageReference r1 = ImageReference.of("ubuntu:bionic");

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/Regex.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ final class Regex implements CharSequence {
5050
private static final Regex PATH_COMPONENT;
5151
static {
5252
Regex segment = Regex.of("[a-z0-9]+");
53-
Regex separator = Regex.group("[._]|__|[-]*");
53+
Regex separator = Regex.group("[._-]{1,2}");
5454
Regex separatedSegment = Regex.group(separator, segment).oneOrMoreTimes();
5555
PATH_COMPONENT = Regex.of(segment, Regex.group(separatedSegment).zeroOrOnce());
5656
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageReferenceTests.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,8 @@
1919
import java.io.File;
2020

2121
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.Timeout;
23+
import org.junit.jupiter.api.Timeout.ThreadMode;
2224

2325
import static org.assertj.core.api.Assertions.assertThat;
2426
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -43,6 +45,16 @@ void ofSimpleName() {
4345
assertThat(reference).hasToString("docker.io/library/ubuntu");
4446
}
4547

48+
@Test
49+
void ofSimpleNameWithSingleCharacterSuffix() {
50+
ImageReference reference = ImageReference.of("ubuntu-a");
51+
assertThat(reference.getDomain()).isEqualTo("docker.io");
52+
assertThat(reference.getName()).isEqualTo("library/ubuntu-a");
53+
assertThat(reference.getTag()).isNull();
54+
assertThat(reference.getDigest()).isNull();
55+
assertThat(reference).hasToString("docker.io/library/ubuntu-a");
56+
}
57+
4658
@Test
4759
void ofLibrarySlashName() {
4860
ImageReference reference = ImageReference.of("library/ubuntu");
@@ -173,7 +185,7 @@ void ofImageNameTagAndDigest() {
173185
}
174186

175187
@Test
176-
void ofWhenHasIllegalCharacter() {
188+
void ofWhenHasIllegalCharacterThrowsException() {
177189
assertThatIllegalArgumentException()
178190
.isThrownBy(() -> ImageReference
179191
.of("registry.example.com/example/example-app:1.6.0-dev.2.uncommitted+wip.foo.c75795d"))
@@ -188,6 +200,14 @@ void ofWhenContainsUpperCaseThrowsException() {
188200
.withMessageContaining("Unable to parse image reference");
189201
}
190202

203+
@Test
204+
@Timeout(value = 1, threadMode = ThreadMode.SEPARATE_THREAD)
205+
void ofWhenIsVeryLongAndHasIllegalCharacter() {
206+
assertThatIllegalArgumentException().isThrownBy(() -> ImageReference
207+
.of("docker.io/library/this-image-has-a-long-name-with-an-invalid-tag-which-is-at-danger-of-catastrophic-backtracking:1.0.0+1234"))
208+
.withMessageContaining("Unable to parse image reference");
209+
}
210+
191211
@Test
192212
void forJarFile() {
193213
assertForJarFile("spring-boot.2.0.0.BUILD-SNAPSHOT.jar", "library/spring-boot", "2.0.0.BUILD-SNAPSHOT");

0 commit comments

Comments
 (0)