From 1b25a1506a4b1f2c3cf2d38dc79866c89ffc11fe Mon Sep 17 00:00:00 2001 From: Kasper Bisgaard Date: Wed, 13 Mar 2024 10:20:27 +0100 Subject: [PATCH] Allow UriTemplate to be built with an empty template See gh-32432 --- .../org/springframework/web/util/UriTemplate.java | 2 +- .../springframework/web/util/UriTemplateTests.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 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(); 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)); + } + }