Browse Source

Deprecate and set trailingSlash option to false

Closes gh-28552
pull/28544/merge
rstoyanchev 3 years ago
parent
commit
b312eca391
  1. 5
      spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcWebTestClient.java
  2. 3
      spring-test/src/main/java/org/springframework/test/web/servlet/client/StandaloneMockMvcSpec.java
  3. 4
      spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java
  4. 4
      spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/FormContentTests.java
  5. 3
      spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java
  6. 13
      spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternParser.java
  7. 3
      spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternRouteMatcher.java
  8. 7
      spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java
  9. 10
      spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java
  10. 3
      spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java
  11. 14
      spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java
  12. 12
      spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java
  13. 3
      spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java
  14. 10
      spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/PatternsRequestConditionTests.java
  15. 6
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java
  16. 6
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java
  17. 3
      spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java
  18. 6
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java
  19. 4
      spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc.xsd
  20. 5
      spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java
  21. 8
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java
  22. 9
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java
  23. 2
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java
  24. 12
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java
  25. 2
      spring-webmvc/src/test/resources/org/springframework/web/servlet/handler/map2.xml
  26. 8
      src/docs/asciidoc/web/webflux.adoc
  27. 1
      src/docs/asciidoc/web/webmvc.adoc

5
spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcWebTestClient.java

@ -1,5 +1,5 @@ @@ -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.
@ -358,7 +358,10 @@ public interface MockMvcWebTestClient { @@ -358,7 +358,10 @@ public interface MockMvcWebTestClient {
* Whether to match trailing slashes.
* <p>This is delegated to
* {@link StandaloneMockMvcBuilder#setUseTrailingSlashPatternMatch(boolean)}.
* @deprecated as of 6.0, see
* {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
@Deprecated
ControllerSpec useTrailingSlashPatternMatch(boolean useTrailingSlashPatternMatch);
/**

3
spring-test/src/main/java/org/springframework/test/web/servlet/client/StandaloneMockMvcSpec.java

@ -1,5 +1,5 @@ @@ -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.
@ -152,6 +152,7 @@ class StandaloneMockMvcSpec extends AbstractMockMvcServerSpec<MockMvcWebTestClie @@ -152,6 +152,7 @@ class StandaloneMockMvcSpec extends AbstractMockMvcServerSpec<MockMvcWebTestClie
return this;
}
@SuppressWarnings("deprecation")
@Override
public StandaloneMockMvcSpec useTrailingSlashPatternMatch(boolean useTrailingSlashPatternMatch) {
this.mockMvcBuilder.setUseTrailingSlashPatternMatch(useTrailingSlashPatternMatch);

4
spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java

@ -343,8 +343,10 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM @@ -343,8 +343,10 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
/**
* 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}.
* @deprecated as of 6.0, see
* {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
@Deprecated
public StandaloneMockMvcBuilder setUseTrailingSlashPatternMatch(boolean useTrailingSlashPatternMatch) {
this.useTrailingSlashPatternMatch = useTrailingSlashPatternMatch;
return this;

4
spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/FormContentTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@ -50,7 +50,7 @@ public class FormContentTests { @@ -50,7 +50,7 @@ public class FormContentTests {
@RestController
private static class Spr15753Controller {
@PutMapping
@PutMapping("/")
public String test(Data d) {
return String.format("d1:%s, d2:%s.", d.getD1(), d.getD2());
}

3
spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java

@ -1,5 +1,5 @@ @@ -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.
@ -150,6 +150,7 @@ public class PathPattern implements Comparable<PathPattern> { @@ -150,6 +150,7 @@ public class PathPattern implements Comparable<PathPattern> {
private boolean catchAll = false;
@SuppressWarnings("deprecation")
PathPattern(String patternText, PathPatternParser parser, @Nullable PathElement head) {
this.patternString = patternText;
this.parser = parser;

13
spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternParser.java

@ -1,5 +1,5 @@ @@ -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.
@ -34,7 +34,7 @@ import org.springframework.http.server.PathContainer; @@ -34,7 +34,7 @@ import org.springframework.http.server.PathContainer;
*/
public class PathPatternParser {
private boolean matchOptionalTrailingSeparator = true;
private boolean matchOptionalTrailingSeparator = false;
private boolean caseSensitive = true;
@ -48,15 +48,22 @@ public class PathPatternParser { @@ -48,15 +48,22 @@ public class PathPatternParser {
* will also match request paths with a trailing slash. If set to
* {@code false} a {@code PathPattern} will only match request paths with
* a trailing slash.
* <p>The default 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 transparent support for trailing slashes is deprecated as of
* 6.0 in favor of configuring explicit redirects through a proxy,
* Servlet/web filter, or a controller.
*/
@Deprecated
public void setMatchOptionalTrailingSeparator(boolean matchOptionalTrailingSeparator) {
this.matchOptionalTrailingSeparator = matchOptionalTrailingSeparator;
}
/**
* Whether optional trailing slashing match is enabled.
* @deprecated as of 6.0 together with {@link #setMatchOptionalTrailingSeparator(boolean)}.
*/
@Deprecated
public boolean isMatchOptionalTrailingSeparator() {
return this.matchOptionalTrailingSeparator;
}

3
spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternRouteMatcher.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@ -48,7 +48,6 @@ public class PathPatternRouteMatcher implements RouteMatcher { @@ -48,7 +48,6 @@ public class PathPatternRouteMatcher implements RouteMatcher {
public PathPatternRouteMatcher() {
this.parser = new PathPatternParser();
this.parser.setPathOptions(PathContainer.Options.MESSAGE_ROUTE);
this.parser.setMatchOptionalTrailingSeparator(false);
}
/**

7
spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java

@ -1,5 +1,5 @@ @@ -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.
@ -99,6 +99,7 @@ public class PathPatternTests { @@ -99,6 +99,7 @@ public class PathPatternTests {
assertThat(pp.matches(toPathContainer(path))).isFalse();
}
@SuppressWarnings("deprecation")
@Test
public void optionalTrailingSeparators() {
PathPattern pp;
@ -438,6 +439,7 @@ public class PathPatternTests { @@ -438,6 +439,7 @@ public class PathPatternTests {
checkCapture("///{foo}///bar", "///one///bar", "foo", "one");
}
@SuppressWarnings("deprecation")
@Test
public void wildcards() {
checkMatches("/*/bar", "/foo/bar");
@ -725,6 +727,7 @@ public class PathPatternTests { @@ -725,6 +727,7 @@ public class PathPatternTests {
}
@Test
@SuppressWarnings("deprecation")
public void extractUriTemplateVariables_spr15264() {
PathPattern pp;
pp = new PathPatternParser().parse("/{foo}");
@ -1145,6 +1148,7 @@ public class PathPatternTests { @@ -1145,6 +1148,7 @@ public class PathPatternTests {
return parse(pattern).matchAndExtract(PathPatternTests.toPathContainer(path));
}
@SuppressWarnings("deprecation")
private PathPattern parse(String path) {
PathPatternParser pp = new PathPatternParser();
pp.setMatchOptionalTrailingSeparator(true);
@ -1158,6 +1162,7 @@ public class PathPatternTests { @@ -1158,6 +1162,7 @@ public class PathPatternTests {
return PathContainer.parsePath(path);
}
@SuppressWarnings("deprecation")
private void checkMatches(String uriTemplate, String path) {
PathPatternParser parser = new PathPatternParser();
parser.setMatchOptionalTrailingSeparator(true);

10
spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.
@ -21,6 +21,7 @@ import java.util.Map; @@ -21,6 +21,7 @@ import java.util.Map;
import java.util.function.Predicate;
import org.springframework.lang.Nullable;
import org.springframework.web.util.pattern.PathPatternParser;
/**
* Assist with configuring {@code HandlerMapping}'s with path matching options.
@ -55,8 +56,12 @@ public class PathMatchConfigurer { @@ -55,8 +56,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;
@ -83,6 +88,7 @@ public class PathMatchConfigurer { @@ -83,6 +88,7 @@ public class PathMatchConfigurer {
@Nullable
@Deprecated
protected Boolean isUseTrailingSlashMatch() {
return this.trailingSlashMatch;
}

3
spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java

@ -1,5 +1,5 @@ @@ -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.
@ -142,6 +142,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { @@ -142,6 +142,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
return mapping;
}
@SuppressWarnings("deprecation")
private void configureAbstractHandlerMapping(AbstractHandlerMapping mapping, PathMatchConfigurer configurer) {
mapping.setCorsConfigurations(getCorsConfigurations());
Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();

14
spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java

@ -1,5 +1,5 @@ @@ -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.
@ -58,7 +58,7 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport @@ -58,7 +58,7 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport
LogDelegateFactory.getHiddenLog(HandlerMapping.class.getName() + ".Mappings");
private final PathPatternParser patternParser;
private final PathPatternParser patternParser = new PathPatternParser();
@Nullable
private CorsConfigurationSource corsConfigurationSource;
@ -71,11 +71,6 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport @@ -71,11 +71,6 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport
private String beanName;
public AbstractHandlerMapping() {
this.patternParser = new PathPatternParser();
}
/**
* Shortcut method for setting the same property on the underlying pattern
* parser in use. For more details see:
@ -98,7 +93,12 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport @@ -98,7 +93,12 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport
* <li>{@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)} --
* the trailing slash option, including its default value.
* </ul>
* <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 trailingSlashMatch) {
this.patternParser.setMatchOptionalTrailingSeparator(trailingSlashMatch);
}

12
spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java

@ -1,5 +1,5 @@ @@ -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.
@ -110,7 +110,7 @@ public class WebFluxConfigurationSupportTests { @@ -110,7 +110,7 @@ public class WebFluxConfigurationSupportTests {
PathPatternParser patternParser = mapping.getPathPatternParser();
assertThat(patternParser).isNotNull();
boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
assertThat(matchOptionalTrailingSlash).isTrue();
assertThat(matchOptionalTrailingSlash).isFalse();
name = "webFluxContentTypeResolver";
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
@ -124,18 +124,11 @@ public class WebFluxConfigurationSupportTests { @@ -124,18 +124,11 @@ public class WebFluxConfigurationSupportTests {
@Test
public void customPathMatchConfig() {
ApplicationContext context = loadConfig(CustomPatchMatchConfig.class);
final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
ReflectionUtils.makeAccessible(field);
String name = "requestMappingHandlerMapping";
RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
assertThat(mapping).isNotNull();
PathPatternParser patternParser = mapping.getPathPatternParser();
assertThat(patternParser).isNotNull();
boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
assertThat(matchOptionalTrailingSlash).isFalse();
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
assertThat(map.size()).isEqualTo(1);
assertThat(map.keySet().iterator().next().getPatternsCondition().getPatterns())
@ -323,7 +316,6 @@ public class WebFluxConfigurationSupportTests { @@ -323,7 +316,6 @@ public class WebFluxConfigurationSupportTests {
@Override
public void configurePathMatching(PathMatchConfigurer configurer) {
configurer.setUseTrailingSlashMatch(false);
configurer.addPathPrefix("/api", HandlerTypePredicate.forAnnotation(RestController.class));
}

3
spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java

@ -1,5 +1,5 @@ @@ -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.
@ -56,7 +56,6 @@ public class SimpleUrlHandlerMappingTests { @@ -56,7 +56,6 @@ public class SimpleUrlHandlerMappingTests {
testUrl("/welcome.html", mainController, handlerMapping, "");
testUrl("/welcome.x", otherController, handlerMapping, "welcome.x");
testUrl("/welcome/", otherController, handlerMapping, "welcome");
testUrl("/show.html", mainController, handlerMapping, "");
testUrl("/bookseats.html", mainController, handlerMapping, "");
}

10
spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/PatternsRequestConditionTests.java

@ -1,5 +1,5 @@ @@ -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.
@ -107,10 +107,14 @@ public class PatternsRequestConditionTests { @@ -107,10 +107,14 @@ public class PatternsRequestConditionTests {
}
@Test
@SuppressWarnings("deprecation")
public void matchTrailingSlash() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/"));
PatternsRequestCondition condition = createPatternsCondition("/foo");
PathPatternParser patternParser = new PathPatternParser();
patternParser.setMatchOptionalTrailingSeparator(true);
PatternsRequestCondition condition = new PatternsRequestCondition(patternParser.parse("/foo"));
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
assertThat(match).isNotNull();
@ -118,7 +122,7 @@ public class PatternsRequestConditionTests { @@ -118,7 +122,7 @@ public class PatternsRequestConditionTests {
.as("Should match by default")
.isEqualTo("/foo");
condition = createPatternsCondition("/foo");
condition = new PatternsRequestCondition(patternParser.parse("/foo"));
match = condition.getMatchingCondition(exchange);
assertThat(match).isNotNull();

6
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java

@ -119,10 +119,6 @@ public class RequestMappingInfoHandlerMappingTests { @@ -119,10 +119,6 @@ public class RequestMappingInfoHandlerMappingTests {
ServerWebExchange exchange = MockServerWebExchange.from(get(""));
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
assertThat(hm.getMethod()).isEqualTo(expected);
exchange = MockServerWebExchange.from(get("/"));
hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
assertThat(hm.getMethod()).isEqualTo(expected);
}
@Test
@ -157,7 +153,6 @@ public class RequestMappingInfoHandlerMappingTests { @@ -157,7 +153,6 @@ public class RequestMappingInfoHandlerMappingTests {
@Test // SPR-8462
public void getHandlerMediaTypeNotSupported() {
testHttpMediaTypeNotSupportedException("/person/1");
testHttpMediaTypeNotSupportedException("/person/1/");
testHttpMediaTypeNotSupportedException("/person/1.json");
}
@ -175,7 +170,6 @@ public class RequestMappingInfoHandlerMappingTests { @@ -175,7 +170,6 @@ public class RequestMappingInfoHandlerMappingTests {
@Test // SPR-8462
public void getHandlerTestMediaTypeNotAcceptable() {
testMediaTypeNotAcceptable("/persons");
testMediaTypeNotAcceptable("/persons/");
}
@Test // SPR-12854

6
spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java

@ -106,8 +106,12 @@ public class PathMatchConfigurer { @@ -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;

3
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java

@ -104,7 +104,10 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i @@ -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) {

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

@ -140,8 +140,12 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi @@ -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) {

4
spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc.xsd

@ -52,7 +52,9 @@ @@ -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>

5
spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java

@ -117,11 +117,6 @@ public class SimpleUrlHandlerMappingTests { @@ -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);

8
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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();

9
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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 { @@ -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");
}

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

@ -3849,7 +3849,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl @@ -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();

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

@ -1,5 +1,5 @@ @@ -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 @@ -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 @@ -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);

2
spring-webmvc/src/test/resources/org/springframework/web/servlet/handler/map2.xml

@ -6,7 +6,6 @@ @@ -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 @@ @@ -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>

8
src/docs/asciidoc/web/webflux.adoc

@ -4310,9 +4310,7 @@ The following example shows how to use `PathMatchConfigurer`: @@ -4310,9 +4310,7 @@ The following example shows how to use `PathMatchConfigurer`:
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer
.setUseCaseSensitiveMatch(true)
.setUseTrailingSlashMatch(false)
.addPathPrefix("/api",
HandlerTypePredicate.forAnnotation(RestController.class));
.addPathPrefix("/api", HandlerTypePredicate.forAnnotation(RestController.class));
}
}
----
@ -4327,9 +4325,7 @@ The following example shows how to use `PathMatchConfigurer`: @@ -4327,9 +4325,7 @@ The following example shows how to use `PathMatchConfigurer`:
fun configurePathMatch(configurer: PathMatchConfigurer) {
configurer
.setUseCaseSensitiveMatch(true)
.setUseTrailingSlashMatch(false)
.addPathPrefix("/api",
HandlerTypePredicate.forAnnotation(RestController::class.java))
.addPathPrefix("/api", HandlerTypePredicate.forAnnotation(RestController::class.java))
}
}
----

1
src/docs/asciidoc/web/webmvc.adoc

@ -6030,7 +6030,6 @@ The following example shows how to customize path matching in XML configuration: @@ -6030,7 +6030,6 @@ The following example shows how to customize path matching in XML configuration:
----
<mvc:annotation-driven>
<mvc:path-matching
trailing-slash="false"
path-helper="pathHelper"
path-matcher="pathMatcher"/>
</mvc:annotation-driven>

Loading…
Cancel
Save