MvcUriComponentsBuilder prepends slash

See gh-24143
This commit is contained in:
Astushi Yoshikawa
2019-12-05 21:47:23 +09:00
committed by Rossen Stoyanchev
parent 1dd5db42ab
commit 53b39eb753
2 changed files with 39 additions and 4 deletions

View File

@@ -434,6 +434,20 @@ public class MvcUriComponentsBuilderTests {
assertThat(url).isEqualTo("/base/people/_%2B_/addresses/DE%3BFR");
}
@Test
public void fromMappingNameWithNonSlashPath() {
initWebApplicationContext(NonSlashPathWebConfig.class);
this.request.setServerName("example.org");
this.request.setServerPort(9999);
this.request.setContextPath("/base");
String mappingName = "NSPC#getAddressesForCountry";
String url = fromMappingName(mappingName).arg(0, "DE;FR").encode().buildAndExpand("_+_");
assertThat(url).isEqualTo("/base/people/DE%3BFR");
}
@Test
public void fromControllerWithPrefix() {
@@ -499,6 +513,15 @@ public class MvcUriComponentsBuilderTests {
}
@RequestMapping({"people"})
static class NonSlashPathController {
@RequestMapping("/{country}")
HttpEntity<Void> getAddressesForCountry(@PathVariable String country) {
return null;
}
}
@RequestMapping({"/persons", "/people"})
private class InvalidController {
}
@@ -622,6 +645,16 @@ public class MvcUriComponentsBuilderTests {
}
@EnableWebMvc
static class NonSlashPathWebConfig implements WebMvcConfigurer {
@Bean
public NonSlashPathController controller() {
return new NonSlashPathController();
}
}
@EnableWebMvc
static class PathPrefixWebConfig implements WebMvcConfigurer {