jsedding commented on code in PR #215:
URL:
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/215#discussion_r3615364845
##########
src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java:
##########
@@ -809,59 +809,57 @@ private static String getMapPath(final String scheme,
final String host, int por
* the {@link ResourcePathIterator} to resolve the resource.
*/
public Resource resolveInternal(final String absPath, final Map<String,
String> parameters) {
- Resource resource = null;
if (absPath != null && !absPath.isEmpty() && !absPath.startsWith("/"))
{
logger.debug("resolveInternal: absolute path expected {} ",
absPath);
- return resource; // resource is null at this point
+ return null;
}
String curPath = absPath;
try {
final ResourcePathIterator it = new ResourcePathIterator(absPath);
+ Resource resource = null;
while (it.hasNext() && resource == null) {
curPath = it.next();
resource = getAbsoluteResourceInternal(null, curPath,
parameters, true);
}
+ // SLING-627: set the part cut off from the uriPath as
+ // sling.resolutionPathInfo property such that
+ // uriPath = curPath + sling.resolutionPathInfo
+ if (resource != null) {
+
+ final String rpi = absPath.substring(curPath.length());
+
resource.getResourceMetadata().setResolutionPath(absPath.substring(0,
curPath.length()));
+ resource.getResourceMetadata().setResolutionPathInfo(rpi);
+ resource.getResourceMetadata().setParameterMap(parameters);
+
+ logger.debug(
+ "resolveInternal: Found resource {} with path info {}
for {}",
+ new Object[] {resource, rpi, absPath});
+ return resource;
+ }
} catch (final Exception ex) {
throw new SlingException("Problem trying " + curPath + " for
request path " + absPath, ex);
}
- // SLING-627: set the part cut off from the uriPath as
- // sling.resolutionPathInfo property such that
- // uriPath = curPath + sling.resolutionPathInfo
+ // no direct resource found, so we have to drill down into the
+ // resource tree to find a match
+ Resource resource = getAbsoluteResourceInternal(absPath, parameters,
true);
if (resource != null) {
-
- final String rpi = absPath.substring(curPath.length());
-
resource.getResourceMetadata().setResolutionPath(absPath.substring(0,
curPath.length()));
- resource.getResourceMetadata().setResolutionPathInfo(rpi);
- resource.getResourceMetadata().setParameterMap(parameters);
-
- logger.debug(
- "resolveInternal: Found resource {} with path info {} for
{}",
- new Object[] {resource, rpi, absPath});
-
- } else {
-
- String tokenizedPath = absPath;
-
- // no direct resource found, so we have to drill down into the
- // resource tree to find a match
- resource = getAbsoluteResourceInternal(null, "/", parameters,
true);
-
- // no read access on / drilling further down
- // SLING-5638
- if (resource == null) {
- resource = getAbsoluteResourceInternal(absPath, parameters,
true);
- if (resource != null) {
- tokenizedPath =
tokenizedPath.substring(resource.getPath().length());
- }
- }
-
final StringBuilder resolutionPath = new StringBuilder();
+ String tokenizedPath = Objects.equals(resource.getPath(), "/")
+ ? absPath
+ : absPath.substring(resource.getPath().length());
final StringTokenizer tokener = new StringTokenizer(tokenizedPath,
"/");
final int delimCount = StringUtils.countMatches(tokenizedPath,
'/');
final int redundantDelimCount = delimCount - tokener.countTokens();
- while (resource != null && tokener.hasMoreTokens()) {
+ // we found an ancestor resource, so we need to prefix the
resolutionPath with it
+ // unless it is the root path (that would result in a double slash
prefix "//")
+ String resolutionPathPrefix =
resource.getResourceMetadata().getResolutionPath();
+ if (!Objects.equals(resolutionPathPrefix, "/")) {
+ resolutionPath.append(resolutionPathPrefix);
+ }
+
+ while (tokener.hasMoreTokens()) {
Review Comment:
good catch, that was a regression 🙂 it's fixed now and covered with a test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]