Skip to content

Commit 48b2229

Browse files
committed
Fix issue with path matching options
Closes gh-23907
1 parent e0faaa4 commit 48b2229

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handler
153153
if (this.embeddedValueResolver != null) {
154154
prefix = this.embeddedValueResolver.resolveStringValue(prefix);
155155
}
156-
info = RequestMappingInfo.paths(prefix).build().combine(info);
156+
info = RequestMappingInfo.paths(prefix).options(this.config).build().combine(info);
157157
break;
158158
}
159159
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handler
226226
}
227227
String prefix = getPathPrefix(handlerType);
228228
if (prefix != null) {
229-
info = RequestMappingInfo.paths(prefix).build().combine(info);
229+
info = RequestMappingInfo.paths(prefix).options(this.config).build().combine(info);
230230
}
231231
}
232232
return info;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import org.springframework.core.annotation.AliasFor;
3535
import org.springframework.http.MediaType;
36+
import org.springframework.mock.web.test.MockHttpServletRequest;
3637
import org.springframework.stereotype.Controller;
3738
import org.springframework.web.accept.ContentNegotiationManager;
3839
import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
@@ -153,6 +154,24 @@ public void pathPrefix() throws NoSuchMethodException {
153154
assertEquals(Collections.singleton("/api/user/{id}"), info.getPatternsCondition().getPatterns());
154155
}
155156

157+
@Test // gh-23907
158+
public void pathPrefixPreservesPathMatchingSettings() throws NoSuchMethodException {
159+
this.handlerMapping.setUseSuffixPatternMatch(false);
160+
this.handlerMapping.setPathPrefixes(Collections.singletonMap("/api", HandlerTypePredicate.forAnyHandlerType()));
161+
this.handlerMapping.afterPropertiesSet();
162+
163+
Method method = ComposedAnnotationController.class.getMethod("get");
164+
RequestMappingInfo info = this.handlerMapping.getMappingForMethod(method, ComposedAnnotationController.class);
165+
166+
assertNotNull(info);
167+
168+
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/api/get");
169+
assertNotNull(info.getPatternsCondition().getMatchingCondition(request));
170+
171+
request = new MockHttpServletRequest("GET", "/api/get.pdf");
172+
assertNull(info.getPatternsCondition().getMatchingCondition(request));
173+
}
174+
156175
@Test
157176
public void resolveRequestMappingViaComposedAnnotation() throws Exception {
158177
RequestMappingInfo info = assertComposedAnnotationMapping("postJson", "/postJson", RequestMethod.POST);

0 commit comments

Comments
 (0)