#1886 - Avoid trailing slash for links pointing to empty mapping path.
This commit is contained in:
@@ -207,7 +207,7 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer {
|
||||
* @return
|
||||
*/
|
||||
private static String join(String typeMapping, String mapping) {
|
||||
return typeMapping.concat("/").concat(mapping);
|
||||
return mapping.isBlank() ? typeMapping : typeMapping.concat("/").concat(mapping);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -748,7 +748,18 @@ class WebMvcLinkBuilderUnitTest extends TestUtils {
|
||||
linkTo(methodOn(ControllerWithPathVariableCatchAll.class).test("first", it[0])).withSelfRel().getHref())
|
||||
.endsWith(it[1]);
|
||||
});
|
||||
}
|
||||
|
||||
@Test // #1886
|
||||
void doesNotAppendTrailingSlashForEmptyMapping() {
|
||||
|
||||
var controller = methodOn(PersonController.class);
|
||||
|
||||
assertThat(linkTo(controller.getMappingWithoutPath()).toString())
|
||||
.isEqualTo("http://localhost/people");
|
||||
|
||||
assertThat(linkTo(controller.getMappingWithEmptyPath()).toString())
|
||||
.isEqualTo("http://localhost/people");
|
||||
}
|
||||
|
||||
private static UriComponents toComponents(Link link) {
|
||||
@@ -760,7 +771,18 @@ class WebMvcLinkBuilderUnitTest extends TestUtils {
|
||||
}
|
||||
|
||||
@RequestMapping("/people")
|
||||
interface PersonController {}
|
||||
interface PersonController {
|
||||
|
||||
@GetMapping
|
||||
default Object getMappingWithoutPath() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
default Object getMappingWithEmptyPath() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class PersonControllerImpl implements PersonController {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user