From 3f6f5c819a1c0e2c1e3d9e803838a29fc73b2c0a Mon Sep 17 00:00:00 2001 From: Kasper Bisgaard Date: Wed, 13 Mar 2024 10:20:27 +0100 Subject: [PATCH 1/2] Changed assert int UriTemplate to notNull in stad of hasText fixes 3201 --- .../src/main/java/org/springframework/web/util/UriTemplate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java b/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java index 770c6ad7498e..da7ba406d80c 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java @@ -66,7 +66,7 @@ public class UriTemplate implements Serializable { * @param uriTemplate the URI template string */ public UriTemplate(String uriTemplate) { - Assert.hasText(uriTemplate, "'uriTemplate' must not be null"); + Assert.notNull(uriTemplate, "'uriTemplate' must not be null"); this.uriTemplate = uriTemplate; this.uriComponents = UriComponentsBuilder.fromUriString(uriTemplate).build(); From 5cf384228b2ee7f3ec6c310540b839f21f9d9e91 Mon Sep 17 00:00:00 2001 From: Kasper Bisgaard Date: Wed, 13 Mar 2024 12:34:51 +0100 Subject: [PATCH 2/2] Added unittests for UriTemplate --- .../springframework/web/util/UriTemplateTests.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spring-web/src/test/java/org/springframework/web/util/UriTemplateTests.java b/spring-web/src/test/java/org/springframework/web/util/UriTemplateTests.java index 49044594fc20..9e68d7cd406a 100644 --- a/spring-web/src/test/java/org/springframework/web/util/UriTemplateTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/UriTemplateTests.java @@ -27,6 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatNoException; /** * @author Arjen Poutsma @@ -218,4 +219,14 @@ void expandWithAtSign() { assertThat(uri.toString()).isEqualTo("http://localhost/query=foo@bar"); } + @Test + void emptyPathDoesNotThrowException() { + assertThatNoException().isThrownBy(() -> new UriTemplate("")); + } + + @Test + void emptyPathThrowsException() { + assertThatIllegalArgumentException().isThrownBy(() -> new UriTemplate(null)); + } + }