Deprecate and set trailingSlash option to false
Closes gh-28552
This commit is contained in:
@@ -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;
|
||||
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 {
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
|
||||
@Nullable
|
||||
@Deprecated
|
||||
protected Boolean isUseTrailingSlashMatch() {
|
||||
return this.trailingSlashMatch;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void configureAbstractHandlerMapping(AbstractHandlerMapping mapping, PathMatchConfigurer configurer) {
|
||||
mapping.setCorsConfigurations(getCorsConfigurations());
|
||||
Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();
|
||||
|
||||
@@ -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
|
||||
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
|
||||
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
|
||||
* <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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
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 {
|
||||
@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 {
|
||||
|
||||
@Override
|
||||
public void configurePathMatching(PathMatchConfigurer configurer) {
|
||||
configurer.setUseTrailingSlashMatch(false);
|
||||
configurer.addPathPrefix("/api", HandlerTypePredicate.forAnnotation(RestController.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
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, "");
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
|
||||
@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 {
|
||||
.as("Should match by default")
|
||||
.isEqualTo("/foo");
|
||||
|
||||
condition = createPatternsCondition("/foo");
|
||||
condition = new PatternsRequestCondition(patternParser.parse("/foo"));
|
||||
match = condition.getMatchingCondition(exchange);
|
||||
|
||||
assertThat(match).isNotNull();
|
||||
|
||||
@@ -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 {
|
||||
@Test // SPR-8462
|
||||
public void getHandlerMediaTypeNotSupported() {
|
||||
testHttpMediaTypeNotSupportedException("/person/1");
|
||||
testHttpMediaTypeNotSupportedException("/person/1/");
|
||||
testHttpMediaTypeNotSupportedException("/person/1.json");
|
||||
}
|
||||
|
||||
@@ -175,7 +170,6 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
@Test // SPR-8462
|
||||
public void getHandlerTestMediaTypeNotAcceptable() {
|
||||
testMediaTypeNotAcceptable("/persons");
|
||||
testMediaTypeNotAcceptable("/persons/");
|
||||
}
|
||||
|
||||
@Test // SPR-12854
|
||||
|
||||
Reference in New Issue
Block a user