SPR-8898 Allow match by trailing slash in RequestMappingHandlerMapping.

This commit is contained in:
Rossen Stoyanchev
2011-12-08 03:38:50 +00:00
parent 569426dfdf
commit 6f150e4f07
5 changed files with 59 additions and 27 deletions

View File

@@ -106,7 +106,7 @@ public class PatternsRequestConditionTests {
assertNotNull(match);
assertEquals("/{foo}.*", match.getPatterns().iterator().next());
condition = new PatternsRequestCondition(new String[] {"/{foo}"}, null, null, false);
condition = new PatternsRequestCondition(new String[] {"/{foo}"}, null, null, false, false);
match = condition.getMatchingCondition(request);
assertNotNull(match);
@@ -121,15 +121,19 @@ public class PatternsRequestConditionTests {
PatternsRequestCondition match = condition.getMatchingCondition(request);
assertNotNull(match);
assertEquals("/foo/", match.getPatterns().iterator().next());
assertEquals("Should match by default", "/foo/", match.getPatterns().iterator().next());
boolean useSuffixPatternMatch = false;
condition = new PatternsRequestCondition(new String[] {"/foo"}, null, null, useSuffixPatternMatch);
condition = new PatternsRequestCondition(new String[] {"/foo"}, null, null, false, true);
match = condition.getMatchingCondition(request);
assertNotNull(match);
assertEquals("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)",
"/foo/", match.getPatterns().iterator().next());
condition = new PatternsRequestCondition(new String[] {"/foo"}, null, null, false, false);
match = condition.getMatchingCondition(request);
assertNull(match);
}
@Test

View File

@@ -317,7 +317,7 @@ public class RequestMappingInfoHandlerMappingTests {
RequestMapping annotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
if (annotation != null) {
return new RequestMappingInfo(
new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true),
new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true),
new RequestMethodsRequestCondition(annotation.method()),
new ParamsRequestCondition(annotation.params()),
new HeadersRequestCondition(annotation.headers()),