提交 48b22292 编写于 作者: R Rossen Stoyanchev

Fix issue with path matching options

Closes gh-23907
上级 e0faaa48
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册