Skip to content

Commit a81ba68

Browse files
committed
Update remaining trailingSlashMatch default value
See gh-28552
1 parent 50240bb commit a81ba68

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -876,7 +876,7 @@ public static class BuilderConfiguration {
876876
@Nullable
877877
private PathMatcher pathMatcher;
878878

879-
private boolean trailingSlashMatch = true;
879+
private boolean trailingSlashMatch = false;
880880

881881
private boolean suffixPatternMatch = false;
882882

@@ -949,15 +949,21 @@ public PathMatcher getPathMatcher() {
949949

950950
/**
951951
* Set whether to apply trailing slash matching in PatternsRequestCondition.
952-
* <p>By default this is set to 'true'.
952+
* <p>The default was changed in 6.0 from {@code true} to {@code false} in
953+
* order to support the deprecation of the property.
954+
* @deprecated as of 6.0, see
955+
* {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
953956
*/
957+
@Deprecated
954958
public void setTrailingSlashMatch(boolean trailingSlashMatch) {
955959
this.trailingSlashMatch = trailingSlashMatch;
956960
}
957961

958962
/**
959963
* Return whether to apply trailing slash matching in PatternsRequestCondition.
964+
* @deprecated as of 6.0 together with {@link #setTrailingSlashMatch(boolean)}
960965
*/
966+
@Deprecated
961967
public boolean useTrailingSlashMatch() {
962968
return this.trailingSlashMatch;
963969
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
8282

8383
private boolean useRegisteredSuffixPatternMatch = false;
8484

85-
private boolean useTrailingSlashMatch = true;
85+
private boolean useTrailingSlashMatch = false;
8686

8787
private Map<String, Predicate<Class<?>>> pathPrefixes = Collections.emptyMap();
8888

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,15 @@ static Stream<Boolean> pathPatternsArguments() {
178178

179179
@PathPatternsParameterizedTest
180180
void emptyValueMapping(boolean usePathPatterns) throws Exception {
181-
initDispatcherServlet(ControllerWithEmptyValueMapping.class, usePathPatterns);
181+
initDispatcherServlet(ControllerWithEmptyValueMapping.class, usePathPatterns, wac -> {
182+
if (!usePathPatterns) {
183+
// UrlPathHelper returns "/" for "",
184+
// so either the mapping has to be "/" or trailingSlashMatch must be on
185+
RootBeanDefinition mappingDef = new RootBeanDefinition(RequestMappingHandlerMapping.class);
186+
mappingDef.getPropertyValues().add("useTrailingSlashMatch", true);
187+
wac.registerBeanDefinition("handlerMapping", mappingDef);
188+
}
189+
});
182190

183191
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
184192
request.setContextPath("/foo");
@@ -190,7 +198,15 @@ void emptyValueMapping(boolean usePathPatterns) throws Exception {
190198

191199
@PathPatternsParameterizedTest
192200
void errorThrownFromHandlerMethod(boolean usePathPatterns) throws Exception {
193-
initDispatcherServlet(ControllerWithErrorThrown.class, usePathPatterns);
201+
initDispatcherServlet(ControllerWithErrorThrown.class, usePathPatterns, wac -> {
202+
if (!usePathPatterns) {
203+
// UrlPathHelper returns "/" for "",
204+
// so either the mapping has to be "/" or trailingSlashMatch must be on
205+
RootBeanDefinition mappingDef = new RootBeanDefinition(RequestMappingHandlerMapping.class);
206+
mappingDef.getPropertyValues().add("useTrailingSlashMatch", true);
207+
wac.registerBeanDefinition("handlerMapping", mappingDef);
208+
}
209+
});
194210

195211
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
196212
request.setContextPath("/foo");

0 commit comments

Comments
 (0)