Deprecate and set trailingSlash option to false
Closes gh-28552
This commit is contained in:
@@ -106,8 +106,12 @@ public class PathMatchConfigurer {
|
||||
/**
|
||||
* Whether to match to URLs irrespective of the presence of a trailing slash.
|
||||
* If enabled a method mapped to "/users" also matches to "/users/".
|
||||
* <p>The default value is {@code 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 PathMatchConfigurer setUseTrailingSlashMatch(Boolean trailingSlashMatch) {
|
||||
this.trailingSlashMatch = trailingSlashMatch;
|
||||
return this;
|
||||
|
||||
@@ -104,7 +104,10 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i
|
||||
* Whether to match to URLs irrespective of the presence of a trailing slash.
|
||||
* If enabled a URL pattern such as "/users" also matches to "/users/".
|
||||
* <p>The default value is {@code false}.
|
||||
* @deprecated as of 6.0, see
|
||||
* {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setUseTrailingSlashMatch(boolean useTrailingSlashMatch) {
|
||||
this.useTrailingSlashMatch = useTrailingSlashMatch;
|
||||
if (getPatternParser() != null) {
|
||||
|
||||
@@ -140,8 +140,12 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
/**
|
||||
* Whether to match to URLs irrespective of the presence of a trailing slash.
|
||||
* If enabled a method mapped to "/users" also matches to "/users/".
|
||||
* <p>The default value is {@code 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 setUseTrailingSlashMatch(boolean useTrailingSlashMatch) {
|
||||
this.useTrailingSlashMatch = useTrailingSlashMatch;
|
||||
if (getPatternParser() != null) {
|
||||
|
||||
@@ -52,7 +52,9 @@
|
||||
<xsd:documentation><![CDATA[
|
||||
Whether to match to URLs irrespective of the presence of a trailing slash.
|
||||
If enabled a method mapped to "/users" also matches to "/users/".
|
||||
The default value is true.
|
||||
|
||||
The default was changed in 6.0 from true to false in order to support the
|
||||
deprecation of the property.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -117,11 +117,6 @@ public class SimpleUrlHandlerMappingTests {
|
||||
assertThat(request.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).isEqualTo("welcome.x");
|
||||
assertThat(request.getAttribute(BEST_MATCHING_HANDLER_ATTRIBUTE)).isEqualTo(otherBean);
|
||||
|
||||
request = PathPatternsTestUtils.initRequest("GET", "/welcome/", usePathPatterns);
|
||||
chain = getHandler(hm, request);
|
||||
assertThat(chain.getHandler()).isSameAs(otherBean);
|
||||
assertThat(request.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).isEqualTo("welcome");
|
||||
|
||||
request = PathPatternsTestUtils.initRequest("GET", "/", usePathPatterns);
|
||||
request.setServletPath("/welcome.html");
|
||||
chain = getHandler(hm, request);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -127,10 +127,14 @@ public class PathPatternsRequestConditionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void matchTrailingSlash() {
|
||||
MockHttpServletRequest request = createRequest("/foo/");
|
||||
|
||||
PathPatternsRequestCondition condition = createCondition("/foo");
|
||||
PathPatternParser patternParser = new PathPatternParser();
|
||||
patternParser.setMatchOptionalTrailingSeparator(true);
|
||||
|
||||
PathPatternsRequestCondition condition = new PathPatternsRequestCondition(patternParser, "/foo");
|
||||
PathPatternsRequestCondition match = condition.getMatchingCondition(request);
|
||||
|
||||
assertThat(match).isNotNull();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-202 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.
|
||||
@@ -138,11 +138,6 @@ class RequestMappingInfoHandlerMappingTests {
|
||||
HandlerMethod handlerMethod = getHandler(mapping, request);
|
||||
|
||||
assertThat(handlerMethod.getMethod()).isEqualTo(this.emptyMethod.getMethod());
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/");
|
||||
handlerMethod = getHandler(mapping, request);
|
||||
|
||||
assertThat(handlerMethod.getMethod()).isEqualTo(this.emptyMethod.getMethod());
|
||||
}
|
||||
|
||||
@PathPatternsParameterizedTest
|
||||
@@ -174,7 +169,6 @@ class RequestMappingInfoHandlerMappingTests {
|
||||
@PathPatternsParameterizedTest // SPR-8462
|
||||
void getHandlerMediaTypeNotSupported(TestRequestMappingInfoHandlerMapping mapping) {
|
||||
testHttpMediaTypeNotSupportedException(mapping, "/person/1");
|
||||
testHttpMediaTypeNotSupportedException(mapping, "/person/1/");
|
||||
testHttpMediaTypeNotSupportedException(mapping, "/person/1.json");
|
||||
}
|
||||
|
||||
@@ -199,7 +193,6 @@ class RequestMappingInfoHandlerMappingTests {
|
||||
@PathPatternsParameterizedTest // SPR-8462
|
||||
void getHandlerMediaTypeNotAccepted(TestRequestMappingInfoHandlerMapping mapping) {
|
||||
testHttpMediaTypeNotAcceptableException(mapping, "/persons");
|
||||
testHttpMediaTypeNotAcceptableException(mapping, "/persons/");
|
||||
if (mapping.getPatternParser() == null) {
|
||||
testHttpMediaTypeNotAcceptableException(mapping, "/persons.json");
|
||||
}
|
||||
|
||||
@@ -3849,7 +3849,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Controller
|
||||
static class HttpHeadersResponseController {
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public HttpHeaders create() throws URISyntaxException {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -225,11 +225,6 @@ public class UriTemplateServletAnnotationControllerHandlerMethodTests extends Ab
|
||||
getServlet().service(request, response);
|
||||
assertThat(response.getContentAsString()).isEqualTo("list");
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/hotels/");
|
||||
response = new MockHttpServletResponse();
|
||||
getServlet().service(request, response);
|
||||
assertThat(response.getContentAsString()).isEqualTo("list");
|
||||
|
||||
request = new MockHttpServletRequest("POST", "/hotels");
|
||||
response = new MockHttpServletResponse();
|
||||
getServlet().service(request, response);
|
||||
@@ -240,11 +235,6 @@ public class UriTemplateServletAnnotationControllerHandlerMethodTests extends Ab
|
||||
getServlet().service(request, response);
|
||||
assertThat(response.getContentAsString()).isEqualTo("show-42");
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/hotels/42/");
|
||||
response = new MockHttpServletResponse();
|
||||
getServlet().service(request, response);
|
||||
assertThat(response.getContentAsString()).isEqualTo("show-42");
|
||||
|
||||
request = new MockHttpServletRequest("PUT", "/hotels/42");
|
||||
response = new MockHttpServletResponse();
|
||||
getServlet().service(request, response);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
|
||||
<property name="defaultHandler"><ref bean="starController"/></property>
|
||||
<property name="rootHandler"><ref bean="mainController"/></property>
|
||||
<property name="useTrailingSlashMatch" value="true"/>
|
||||
<property name="urlMap">
|
||||
<map>
|
||||
<entry key="/welcome*"><ref bean="otherController"/></entry>
|
||||
@@ -23,7 +22,6 @@
|
||||
<bean id="urlMappingWithProps" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
|
||||
<property name="defaultHandler"><ref bean="starController"/></property>
|
||||
<property name="rootHandler"><ref bean="mainController"/></property>
|
||||
<property name="useTrailingSlashMatch" value="true"/>
|
||||
<property name="mappings"><ref bean="mappings"/></property>
|
||||
</bean>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user