From 32db1a1680b60852d2dc409f23160bab6764b7c5 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Fri, 13 Dec 2024 14:10:19 +0000 Subject: [PATCH] Remove WebFlux trailing slash match See gh-34036 --- .../reactive/config/PathMatchConfigurer.java | 27 +--------------- .../config/WebFluxConfigurationSupport.java | 5 --- .../handler/AbstractHandlerMapping.java | 18 ----------- .../WebFluxConfigurationSupportTests.java | 30 ----------------- .../PatternsRequestConditionTests.java | 32 ------------------- 5 files changed, 1 insertion(+), 111 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java index 66e09b069b3..58cc38a7448 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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,7 +21,6 @@ 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. @@ -32,10 +31,6 @@ import org.springframework.web.util.pattern.PathPatternParser; */ public class PathMatchConfigurer { - @Nullable - private Boolean trailingSlashMatch; - - @Nullable private Boolean caseSensitiveMatch; @@ -53,20 +48,6 @@ public class PathMatchConfigurer { return this; } - /** - * 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 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(since = "6.0") - public PathMatchConfigurer setUseTrailingSlashMatch(Boolean trailingSlashMatch) { - this.trailingSlashMatch = trailingSlashMatch; - return this; - } - /** * Configure a path prefix to apply to matching controller methods. *

Prefixes are used to enrich the mappings of every {@code @RequestMapping} @@ -87,12 +68,6 @@ public class PathMatchConfigurer { } - @Nullable - @Deprecated - protected Boolean isUseTrailingSlashMatch() { - return this.trailingSlashMatch; - } - @Nullable protected Boolean isUseCaseSensitiveMatch() { return this.caseSensitiveMatch; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java index eccef7cfe93..57b71e8a99b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java @@ -154,13 +154,8 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { return mapping; } - @SuppressWarnings("deprecation") private void configureAbstractHandlerMapping(AbstractHandlerMapping mapping, PathMatchConfigurer configurer) { mapping.setCorsConfigurations(getCorsConfigurations()); - Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch(); - if (useTrailingSlashMatch != null) { - mapping.setUseTrailingSlashMatch(useTrailingSlashMatch); - } Boolean useCaseSensitiveMatch = configurer.isUseCaseSensitiveMatch(); if (useCaseSensitiveMatch != null) { mapping.setUseCaseSensitiveMatch(useCaseSensitiveMatch); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java index 643e9dda2a3..c179d49e33e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java @@ -85,24 +85,6 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport this.patternParser.setCaseSensitive(caseSensitiveMatch); } - /** - * Shortcut method for setting the same property on the underlying pattern - * parser in use. For more details see: - *

- *

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(since = "6.0") - public void setUseTrailingSlashMatch(boolean trailingSlashMatch) { - this.patternParser.setMatchOptionalTrailingSeparator(trailingSlashMatch); - } - /** * Return the {@link PathPatternParser} instance that is used for * {@link #setCorsConfigurations(Map) CORS configuration checks}. diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java index 05414812113..aeadb7de415 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java @@ -16,7 +16,6 @@ package org.springframework.web.reactive.config; -import java.lang.reflect.Field; import java.nio.ByteBuffer; import java.security.Principal; import java.util.Collections; @@ -48,7 +47,6 @@ import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; import org.springframework.util.MultiValueMap; -import org.springframework.util.ReflectionUtils; import org.springframework.validation.Validator; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -71,9 +69,7 @@ import org.springframework.web.reactive.result.view.ViewResolutionResultHandler; import org.springframework.web.reactive.result.view.ViewResolver; import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver; -import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebHandler; -import org.springframework.web.testfixture.server.MockServerWebExchange; import org.springframework.web.util.pattern.PathPatternParser; import static org.assertj.core.api.Assertions.assertThat; @@ -87,7 +83,6 @@ import static org.springframework.http.MediaType.APPLICATION_PROTOBUF; import static org.springframework.http.MediaType.APPLICATION_XML; import static org.springframework.http.MediaType.IMAGE_PNG; import static org.springframework.http.MediaType.TEXT_PLAIN; -import static org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.get; /** * Tests for {@link WebFluxConfigurationSupport}. @@ -96,31 +91,6 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe */ class WebFluxConfigurationSupportTests { - @Test - void requestMappingHandlerMapping() { - ApplicationContext context = loadConfig(WebFluxConfig.class); - Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator"); - assertThat(field).isNotNull(); - ReflectionUtils.makeAccessible(field); - - String name = "requestMappingHandlerMapping"; - RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class); - assertThat(mapping).isNotNull(); - - assertThat(mapping.getOrder()).isEqualTo(0); - - PathPatternParser patternParser = mapping.getPathPatternParser(); - assertThat(patternParser).hasFieldOrPropertyWithValue("matchOptionalTrailingSeparator", false); - - name = "webFluxContentTypeResolver"; - RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class); - assertThat(mapping.getContentTypeResolver()).isSameAs(resolver); - - ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON)); - assertThat(resolver.resolveMediaTypes(exchange)) - .isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON)); - } - @Test void customPathMatchConfig() { ApplicationContext context = loadConfig(CustomPatchMatchConfig.class); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/PatternsRequestConditionTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/PatternsRequestConditionTests.java index 5a4bc69fd8e..802491d08be 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/PatternsRequestConditionTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/PatternsRequestConditionTests.java @@ -104,38 +104,6 @@ class PatternsRequestConditionTests { assertThat(match).isEqualTo(expected); } - @Test - @SuppressWarnings("deprecation") - public void matchTrailingSlash() { - MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/")); - - PathPatternParser patternParser = new PathPatternParser(); - patternParser.setMatchOptionalTrailingSeparator(true); - - PatternsRequestCondition condition = new PatternsRequestCondition(patternParser.parse("/foo")); - PatternsRequestCondition match = condition.getMatchingCondition(exchange); - - assertThat(match).isNotNull(); - assertThat(match.getPatterns().iterator().next().getPatternString()) - .as("Should match by default") - .isEqualTo("/foo"); - - condition = new PatternsRequestCondition(patternParser.parse("/foo")); - match = condition.getMatchingCondition(exchange); - - assertThat(match).isNotNull(); - assertThat(match.getPatterns().iterator().next().getPatternString()) - .as("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)") - .isEqualTo("/foo"); - - PathPatternParser parser = new PathPatternParser(); - parser.setMatchOptionalTrailingSeparator(false); - condition = new PatternsRequestCondition(parser.parse("/foo")); - match = condition.getMatchingCondition(MockServerWebExchange.from(get("/foo/"))); - - assertThat(match).isNull(); - } - @Test void matchPatternContainsExtension() { PatternsRequestCondition condition = createPatternsCondition("/foo.jpg");