Skip to content

Commit 1b25a15

Browse files
bsgrdsnicoll
authored andcommitted
Allow UriTemplate to be built with an empty template
See gh-32432
1 parent 723c94e commit 1b25a15

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spring-web/src/main/java/org/springframework/web/util/UriTemplate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class UriTemplate implements Serializable {
6666
* @param uriTemplate the URI template string
6767
*/
6868
public UriTemplate(String uriTemplate) {
69-
Assert.hasText(uriTemplate, "'uriTemplate' must not be null");
69+
Assert.notNull(uriTemplate, "'uriTemplate' must not be null");
7070
this.uriTemplate = uriTemplate;
7171
this.uriComponents = UriComponentsBuilder.fromUriString(uriTemplate).build();
7272

spring-web/src/test/java/org/springframework/web/util/UriTemplateTests.java

+11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import static org.assertj.core.api.Assertions.assertThat;
2929
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
30+
import static org.assertj.core.api.Assertions.assertThatNoException;
3031

3132
/**
3233
* @author Arjen Poutsma
@@ -218,4 +219,14 @@ void expandWithAtSign() {
218219
assertThat(uri.toString()).isEqualTo("http://localhost/query=foo@bar");
219220
}
220221

222+
@Test
223+
void emptyPathDoesNotThrowException() {
224+
assertThatNoException().isThrownBy(() -> new UriTemplate(""));
225+
}
226+
227+
@Test
228+
void emptyPathThrowsException() {
229+
assertThatIllegalArgumentException().isThrownBy(() -> new UriTemplate(null));
230+
}
231+
221232
}

0 commit comments

Comments
 (0)