SPR-5636 - @RequestMapping matching should be insensitive to trailing slashes
This commit is contained in:
@@ -503,7 +503,15 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
|
||||
if (pattern.equals(lookupPath) || pathMatcher.match(pattern, lookupPath)) {
|
||||
return true;
|
||||
}
|
||||
return !(pattern.indexOf('.') != -1) && pathMatcher.match(pattern + ".*", lookupPath);
|
||||
boolean hasSuffix = pattern.indexOf('.') != -1;
|
||||
if (!hasSuffix && pathMatcher.match(pattern + ".*", lookupPath)) {
|
||||
return true;
|
||||
}
|
||||
boolean endsWithSlash = pattern.endsWith("/");
|
||||
if (!endsWithSlash && pathMatcher.match(pattern + "/", lookupPath)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkParameters(RequestMappingInfo mapping, HttpServletRequest request) {
|
||||
|
||||
@@ -86,10 +86,10 @@ public class DefaultAnnotationHandlerMapping extends AbstractDetectingUrlHandler
|
||||
|
||||
/**
|
||||
* Set whether to register paths using the default suffix pattern as well:
|
||||
* i.e. whether "/users" should be registered as "/users.*" too.
|
||||
* i.e. whether "/users" should be registered as "/users.*" and "/users/" too.
|
||||
* <p>Default is "true". Turn this convention off if you intend to interpret
|
||||
* your <code>@RequestMapping</code> paths strictly.
|
||||
* <p>Note that paths which include a ".xxx" suffix already will not be
|
||||
* <p>Note that paths which include a ".xxx" suffix or end with "/" already will not be
|
||||
* transformed using the default suffix pattern in any case.
|
||||
*/
|
||||
public void setUseDefaultSuffixPattern(boolean useDefaultSuffixPattern) {
|
||||
@@ -168,8 +168,9 @@ public class DefaultAnnotationHandlerMapping extends AbstractDetectingUrlHandler
|
||||
*/
|
||||
protected void addUrlsForPath(Set<String> urls, String path) {
|
||||
urls.add(path);
|
||||
if (this.useDefaultSuffixPattern && path.indexOf('.') == -1) {
|
||||
if (this.useDefaultSuffixPattern && path.indexOf('.') == -1 && !path.endsWith("/")) {
|
||||
urls.add(path + ".*");
|
||||
urls.add(path + "/");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user