You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2021/05/28 15:43:18 UTC

[sling-org-apache-sling-resourceresolver] 02/02: SLING-10432 - regression: incorrect mapping result for aliased pages

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit 6c203087a1d989b9bc8fe8d872b629774b79604e
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri May 28 17:32:28 2021 +0200

    SLING-10432 - regression: incorrect mapping result for aliased pages
    
    - ensure that the path of the resolved resources does not get added to the aliases list
    - try harder to establish a mapping (edge scenario for resolving thee empty path)
    - enable the previously ignored test for this issue
---
 .../resourceresolver/impl/mapping/ResourceMapperImpl.java   | 13 +++++++++++--
 .../impl/mapping/ResourceMapperImplTest.java                |  2 --
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
index b44789d..2216331 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
@@ -164,10 +164,14 @@ public class ResourceMapperImpl implements ResourceMapper {
         // vanity paths are prepended to make sure they get returned last
         mappings.addAll(0, vanityPaths);
 
-        // 7. apply context path if needed
+        // 7. final effort to make sure we have at least one mapped path
+        if ( mappings.isEmpty() && nonDecoratedResource != null )
+            mappings.add(nonDecoratedResource.getPath());
+
+        // 8. apply context path if needed
         mappings.replaceAll(new ApplyContextPath(request));
        
-        // 8. set back the fragment query if needed
+        // 9. set back the fragment query if needed
         if ( fragmentQuery != null ) {
             mappings.replaceAll(path -> path.concat(fragmentQuery));
         }
@@ -218,6 +222,11 @@ public class ResourceMapperImpl implements ResourceMapper {
         
         // and then we have the mapped path to work on
         List<String> mappedPaths = pathBuilder.generatePaths();
+        // specifically exclude the resource's path when generating aliases
+        // usually this is removed the invoking method if the path matches an existing
+        // resource, but for non-existing ones this does not work
+        mappedPaths.remove(nonDecoratedResource.getPath());
+
         logger.debug("map: Alias mapping resolves to paths {}", mappedPaths);
         
         return mappedPaths;
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
index 9ae3c4f..f0639cb 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
@@ -47,7 +47,6 @@ import org.apache.sling.spi.resource.provider.ResourceProvider;
 import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -333,7 +332,6 @@ public class ResourceMapperImplTest {
      * is the alias itself
      */
     @Test
-    @Ignore("SLING-10432")
     public void mapAliasTarget() {
         ExpectedMappings.nonExistingResource("/alias-value")
             .singleMapping("/alias-value")