Refine empty path handling in MvcUriComponentsBuilder
Return "" from methods that obtain controller or method mapping to avoid side effect of a trailing slash appearing. Closes gh-29897
This commit is contained in:
@@ -234,12 +234,19 @@ public class MvcUriComponentsBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMethodNameNotMapped() {
|
||||
UriComponents uriComponents = fromMethodName(UnmappedController.class, "unmappedMethod").build();
|
||||
public void fromMethodNameInUnmappedController() {
|
||||
UriComponents uriComponents = fromMethodName(UnmappedController.class, "requestMappingMethod").build();
|
||||
|
||||
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/");
|
||||
}
|
||||
|
||||
@Test // gh-29897
|
||||
public void fromMethodNameInUnmappedControllerMethod() {
|
||||
UriComponents uriComponents = fromMethodName(UnmappedControllerMethod.class, "getMethod").build();
|
||||
|
||||
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/path");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMethodNameWithCustomBaseUrlViaStaticCall() {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base");
|
||||
@@ -535,7 +542,16 @@ public class MvcUriComponentsBuilderTests {
|
||||
private class UnmappedController {
|
||||
|
||||
@RequestMapping
|
||||
public void unmappedMethod() {
|
||||
public void requestMappingMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/path")
|
||||
private class UnmappedControllerMethod {
|
||||
|
||||
@GetMapping
|
||||
public void getMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user