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

@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -876,7 +876,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
@Nullable
private PathMatcher pathMatcher;
private boolean trailingSlashMatch = true;
private boolean trailingSlashMatch = false;
private boolean suffixPatternMatch = false;
@ -949,15 +949,21 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
/**
* Set whether to apply trailing slash matching in PatternsRequestCondition.
* <p>By default this is set to 'true'.
* <p>The default was changed in 6.0 from {@code true} to {@code false} in
* order to support the deprecation of the property.
* @deprecated as of 6.0, see
* {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
@Deprecated
public void setTrailingSlashMatch(boolean trailingSlashMatch) {
this.trailingSlashMatch = trailingSlashMatch;
}
/**
* Return whether to apply trailing slash matching in PatternsRequestCondition.
* @deprecated as of 6.0 together with {@link #setTrailingSlashMatch(boolean)}
*/
@Deprecated
public boolean useTrailingSlashMatch() {
return this.trailingSlashMatch;
}

View File

@ -82,7 +82,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
private boolean useRegisteredSuffixPatternMatch = false;
private boolean useTrailingSlashMatch = true;
private boolean useTrailingSlashMatch = false;
private Map<String, Predicate<Class<?>>> pathPrefixes = Collections.emptyMap();

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");