Prepend leading slash in ResourceUrlProvider
The getForRequestUrl method of ResourceUrlProvider uses the HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE attribute to determine the relevant portion of the resource URL path. However there are cases when that attribute may not have a leading (e.g. when the current URL was matched to a prefix-based pattern and hence extracted via PathMatcher#extractPathWithinPattern), which interferes with the matching of resource URL paths to patterns. This change ensures a leading slash is present Issue: SPR-12281
This commit is contained in:
@@ -179,6 +179,9 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||
pathWithinMapping = getPathHelper().getLookupPathForRequest(request);
|
||||
}
|
||||
|
||||
// When extracted with PathMatcher, pathWithinMapping won't have leading slash
|
||||
pathWithinMapping = (pathWithinMapping.charAt(0) == '/' ? pathWithinMapping : "/" + pathWithinMapping);
|
||||
|
||||
int index = getPathHelper().getRequestUri(request).indexOf(pathWithinMapping);
|
||||
Assert.state(index != -1, "Failed to determine lookup path: " + requestUrl);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user