Skip to content

Commit 08e7f7e

Browse files
bsgrdsnicoll
authored andcommitted
Allow UriTemplate to be built with an empty template
Closes gh-32437
1 parent b1fafbf commit 08e7f7e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-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.
@@ -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

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-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.
@@ -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
@@ -35,6 +36,16 @@
3536
*/
3637
class UriTemplateTests {
3738

39+
@Test
40+
void emptyPathDoesNotThrowException() {
41+
assertThatNoException().isThrownBy(() -> new UriTemplate(""));
42+
}
43+
44+
@Test
45+
void nullPathThrowsException() {
46+
assertThatIllegalArgumentException().isThrownBy(() -> new UriTemplate(null));
47+
}
48+
3849
@Test
3950
void getVariableNames() {
4051
UriTemplate template = new UriTemplate("/hotels/{hotel}/bookings/{booking}");

0 commit comments

Comments
 (0)