Fix issue with path matching options

Closes gh-23907
This commit is contained in:
Rossen Stoyanchev
2019-11-06 17:39:41 +00:00
parent e0faaa4807
commit 48b22292ff
3 changed files with 21 additions and 2 deletions

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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);