Skip to content

Commit 32db1a1

Browse files
committed
Remove WebFlux trailing slash match
See gh-34036
1 parent 4fd368b commit 32db1a1

File tree

5 files changed

+1
-111
lines changed

5 files changed

+1
-111
lines changed

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

+1-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -21,7 +21,6 @@
2121
import java.util.function.Predicate;
2222

2323
import org.springframework.lang.Nullable;
24-
import org.springframework.web.util.pattern.PathPatternParser;
2524

2625
/**
2726
* Assist with configuring {@code HandlerMapping}'s with path matching options.
@@ -32,10 +31,6 @@
3231
*/
3332
public class PathMatchConfigurer {
3433

35-
@Nullable
36-
private Boolean trailingSlashMatch;
37-
38-
3934
@Nullable
4035
private Boolean caseSensitiveMatch;
4136

@@ -53,20 +48,6 @@ public PathMatchConfigurer setUseCaseSensitiveMatch(Boolean caseSensitiveMatch)
5348
return this;
5449
}
5550

56-
/**
57-
* Whether to match to URLs irrespective of the presence of a trailing slash.
58-
* If enabled a method mapped to "/users" also matches to "/users/".
59-
* <p>The default was changed in 6.0 from {@code true} to {@code false} in
60-
* order to support the deprecation of the property.
61-
* @deprecated as of 6.0, see
62-
* {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
63-
*/
64-
@Deprecated(since = "6.0")
65-
public PathMatchConfigurer setUseTrailingSlashMatch(Boolean trailingSlashMatch) {
66-
this.trailingSlashMatch = trailingSlashMatch;
67-
return this;
68-
}
69-
7051
/**
7152
* Configure a path prefix to apply to matching controller methods.
7253
* <p>Prefixes are used to enrich the mappings of every {@code @RequestMapping}
@@ -87,12 +68,6 @@ public PathMatchConfigurer addPathPrefix(String prefix, Predicate<Class<?>> pred
8768
}
8869

8970

90-
@Nullable
91-
@Deprecated
92-
protected Boolean isUseTrailingSlashMatch() {
93-
return this.trailingSlashMatch;
94-
}
95-
9671
@Nullable
9772
protected Boolean isUseCaseSensitiveMatch() {
9873
return this.caseSensitiveMatch;

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

-5
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,8 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping(
154154
return mapping;
155155
}
156156

157-
@SuppressWarnings("deprecation")
158157
private void configureAbstractHandlerMapping(AbstractHandlerMapping mapping, PathMatchConfigurer configurer) {
159158
mapping.setCorsConfigurations(getCorsConfigurations());
160-
Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();
161-
if (useTrailingSlashMatch != null) {
162-
mapping.setUseTrailingSlashMatch(useTrailingSlashMatch);
163-
}
164159
Boolean useCaseSensitiveMatch = configurer.isUseCaseSensitiveMatch();
165160
if (useCaseSensitiveMatch != null) {
166161
mapping.setUseCaseSensitiveMatch(useCaseSensitiveMatch);

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

-18
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,6 @@ public void setUseCaseSensitiveMatch(boolean caseSensitiveMatch) {
8585
this.patternParser.setCaseSensitive(caseSensitiveMatch);
8686
}
8787

88-
/**
89-
* Shortcut method for setting the same property on the underlying pattern
90-
* parser in use. For more details see:
91-
* <ul>
92-
* <li>{@link #getPathPatternParser()} -- the underlying pattern parser
93-
* <li>{@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)} --
94-
* the trailing slash option, including its default value.
95-
* </ul>
96-
* <p>The default was changed in 6.0 from {@code true} to {@code false} in
97-
* order to support the deprecation of the property.
98-
* @deprecated as of 6.0, see
99-
* {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
100-
*/
101-
@Deprecated(since = "6.0")
102-
public void setUseTrailingSlashMatch(boolean trailingSlashMatch) {
103-
this.patternParser.setMatchOptionalTrailingSeparator(trailingSlashMatch);
104-
}
105-
10688
/**
10789
* Return the {@link PathPatternParser} instance that is used for
10890
* {@link #setCorsConfigurations(Map) CORS configuration checks}.

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

-30
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.web.reactive.config;
1818

19-
import java.lang.reflect.Field;
2019
import java.nio.ByteBuffer;
2120
import java.security.Principal;
2221
import java.util.Collections;
@@ -48,7 +47,6 @@
4847
import org.springframework.util.MimeType;
4948
import org.springframework.util.MimeTypeUtils;
5049
import org.springframework.util.MultiValueMap;
51-
import org.springframework.util.ReflectionUtils;
5250
import org.springframework.validation.Validator;
5351
import org.springframework.web.bind.annotation.GetMapping;
5452
import org.springframework.web.bind.annotation.RequestMapping;
@@ -71,9 +69,7 @@
7169
import org.springframework.web.reactive.result.view.ViewResolver;
7270
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer;
7371
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver;
74-
import org.springframework.web.server.ServerWebExchange;
7572
import org.springframework.web.server.WebHandler;
76-
import org.springframework.web.testfixture.server.MockServerWebExchange;
7773
import org.springframework.web.util.pattern.PathPatternParser;
7874

7975
import static org.assertj.core.api.Assertions.assertThat;
@@ -87,7 +83,6 @@
8783
import static org.springframework.http.MediaType.APPLICATION_XML;
8884
import static org.springframework.http.MediaType.IMAGE_PNG;
8985
import static org.springframework.http.MediaType.TEXT_PLAIN;
90-
import static org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.get;
9186

9287
/**
9388
* Tests for {@link WebFluxConfigurationSupport}.
@@ -96,31 +91,6 @@
9691
*/
9792
class WebFluxConfigurationSupportTests {
9893

99-
@Test
100-
void requestMappingHandlerMapping() {
101-
ApplicationContext context = loadConfig(WebFluxConfig.class);
102-
Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
103-
assertThat(field).isNotNull();
104-
ReflectionUtils.makeAccessible(field);
105-
106-
String name = "requestMappingHandlerMapping";
107-
RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
108-
assertThat(mapping).isNotNull();
109-
110-
assertThat(mapping.getOrder()).isEqualTo(0);
111-
112-
PathPatternParser patternParser = mapping.getPathPatternParser();
113-
assertThat(patternParser).hasFieldOrPropertyWithValue("matchOptionalTrailingSeparator", false);
114-
115-
name = "webFluxContentTypeResolver";
116-
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
117-
assertThat(mapping.getContentTypeResolver()).isSameAs(resolver);
118-
119-
ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON));
120-
assertThat(resolver.resolveMediaTypes(exchange))
121-
.isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
122-
}
123-
12494
@Test
12595
void customPathMatchConfig() {
12696
ApplicationContext context = loadConfig(CustomPatchMatchConfig.class);

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

-32
Original file line numberDiff line numberDiff line change
@@ -104,38 +104,6 @@ void matchSortPatterns() {
104104
assertThat(match).isEqualTo(expected);
105105
}
106106

107-
@Test
108-
@SuppressWarnings("deprecation")
109-
public void matchTrailingSlash() {
110-
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/"));
111-
112-
PathPatternParser patternParser = new PathPatternParser();
113-
patternParser.setMatchOptionalTrailingSeparator(true);
114-
115-
PatternsRequestCondition condition = new PatternsRequestCondition(patternParser.parse("/foo"));
116-
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
117-
118-
assertThat(match).isNotNull();
119-
assertThat(match.getPatterns().iterator().next().getPatternString())
120-
.as("Should match by default")
121-
.isEqualTo("/foo");
122-
123-
condition = new PatternsRequestCondition(patternParser.parse("/foo"));
124-
match = condition.getMatchingCondition(exchange);
125-
126-
assertThat(match).isNotNull();
127-
assertThat(match.getPatterns().iterator().next().getPatternString())
128-
.as("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)")
129-
.isEqualTo("/foo");
130-
131-
PathPatternParser parser = new PathPatternParser();
132-
parser.setMatchOptionalTrailingSeparator(false);
133-
condition = new PatternsRequestCondition(parser.parse("/foo"));
134-
match = condition.getMatchingCondition(MockServerWebExchange.from(get("/foo/")));
135-
136-
assertThat(match).isNull();
137-
}
138-
139107
@Test
140108
void matchPatternContainsExtension() {
141109
PatternsRequestCondition condition = createPatternsCondition("/foo.jpg");

0 commit comments

Comments
 (0)