Fix issue with path matching options
Closes gh-23907
This commit is contained in:
@@ -153,7 +153,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
if (this.embeddedValueResolver != null) {
|
||||
prefix = this.embeddedValueResolver.resolveStringValue(prefix);
|
||||
}
|
||||
info = RequestMappingInfo.paths(prefix).build().combine(info);
|
||||
info = RequestMappingInfo.paths(prefix).options(this.config).build().combine(info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
}
|
||||
String prefix = getPathPrefix(handlerType);
|
||||
if (prefix != null) {
|
||||
info = RequestMappingInfo.paths(prefix).build().combine(info);
|
||||
info = RequestMappingInfo.paths(prefix).options(this.config).build().combine(info);
|
||||
}
|
||||
}
|
||||
return info;
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.accept.ContentNegotiationManager;
|
||||
import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
|
||||
@@ -153,6 +154,24 @@ public class RequestMappingHandlerMappingTests {
|
||||
assertEquals(Collections.singleton("/api/user/{id}"), info.getPatternsCondition().getPatterns());
|
||||
}
|
||||
|
||||
@Test // gh-23907
|
||||
public void pathPrefixPreservesPathMatchingSettings() throws NoSuchMethodException {
|
||||
this.handlerMapping.setUseSuffixPatternMatch(false);
|
||||
this.handlerMapping.setPathPrefixes(Collections.singletonMap("/api", HandlerTypePredicate.forAnyHandlerType()));
|
||||
this.handlerMapping.afterPropertiesSet();
|
||||
|
||||
Method method = ComposedAnnotationController.class.getMethod("get");
|
||||
RequestMappingInfo info = this.handlerMapping.getMappingForMethod(method, ComposedAnnotationController.class);
|
||||
|
||||
assertNotNull(info);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/api/get");
|
||||
assertNotNull(info.getPatternsCondition().getMatchingCondition(request));
|
||||
|
||||
request = new MockHttpServletRequest("GET", "/api/get.pdf");
|
||||
assertNull(info.getPatternsCondition().getMatchingCondition(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRequestMappingViaComposedAnnotation() throws Exception {
|
||||
RequestMappingInfo info = assertComposedAnnotationMapping("postJson", "/postJson", RequestMethod.POST);
|
||||
|
||||
Reference in New Issue
Block a user