Update remaining trailingSlashMatch default value

See gh-28552
This commit is contained in:
rstoyanchev
2022-07-01 18:07:06 +01:00
parent 50240bb609
commit a81ba68da1
3 changed files with 28 additions and 6 deletions

View File

@@ -178,7 +178,15 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
@PathPatternsParameterizedTest
void emptyValueMapping(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ControllerWithEmptyValueMapping.class, usePathPatterns);
initDispatcherServlet(ControllerWithEmptyValueMapping.class, usePathPatterns, wac -> {
if (!usePathPatterns) {
// UrlPathHelper returns "/" for "",
// so either the mapping has to be "/" or trailingSlashMatch must be on
RootBeanDefinition mappingDef = new RootBeanDefinition(RequestMappingHandlerMapping.class);
mappingDef.getPropertyValues().add("useTrailingSlashMatch", true);
wac.registerBeanDefinition("handlerMapping", mappingDef);
}
});
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
request.setContextPath("/foo");
@@ -190,7 +198,15 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
@PathPatternsParameterizedTest
void errorThrownFromHandlerMethod(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ControllerWithErrorThrown.class, usePathPatterns);
initDispatcherServlet(ControllerWithErrorThrown.class, usePathPatterns, wac -> {
if (!usePathPatterns) {
// UrlPathHelper returns "/" for "",
// so either the mapping has to be "/" or trailingSlashMatch must be on
RootBeanDefinition mappingDef = new RootBeanDefinition(RequestMappingHandlerMapping.class);
mappingDef.getPropertyValues().add("useTrailingSlashMatch", true);
wac.registerBeanDefinition("handlerMapping", mappingDef);
}
});
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
request.setContextPath("/foo");