sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-resourcemerger] 28/31: SLING-4878 - Resource Merger: Infinite loop in case a parent resource has one of its children as a supertype
Date Tue, 07 Nov 2017 10:00:09 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.resourcemerger-1.2.10
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcemerger.git

commit 8e5af97dcf551d56dd86eebd42f53047bee4b73d
Author: Radu Cotescu <radu@apache.org>
AuthorDate: Wed Jul 15 08:30:34 2015 +0000

    SLING-4878 - Resource Merger: Infinite loop in case a parent resource has one of its children
as a supertype
    
    * fixed infinite loop if an inheritance loop exists
    (applied patch from Vlad Bailescu)
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/resourcemerger@1691143
13f79535-47bb-0310-9956-ffa450edef68
---
 .../impl/picker/OverridingResourcePicker.java        |  8 +++++++-
 .../impl/OverridingResourceProviderTest.java         | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/resourcemerger/impl/picker/OverridingResourcePicker.java
b/src/main/java/org/apache/sling/resourcemerger/impl/picker/OverridingResourcePicker.java
index 49090ec..40ac7b8 100644
--- a/src/main/java/org/apache/sling/resourcemerger/impl/picker/OverridingResourcePicker.java
+++ b/src/main/java/org/apache/sling/resourcemerger/impl/picker/OverridingResourcePicker.java
@@ -20,7 +20,9 @@ package org.apache.sling.resourcemerger.impl.picker;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
@@ -52,6 +54,7 @@ public class OverridingResourcePicker implements MergedResourcePicker {
     public List<Resource> pickResources(ResourceResolver resolver, String relativePath)
{
         String absPath = "/" + relativePath;
         final List<Resource> resources = new ArrayList<Resource>();
+        final Set<String> roots = new HashSet<String>();
 
         Resource currentTarget = resolver.getResource(absPath);
 
@@ -70,7 +73,9 @@ public class OverridingResourcePicker implements MergedResourcePicker {
                 final Resource inheritanceRootResource = info.resource;
                 final String pathRelativeToInheritanceRoot = info.getPathRelativeToInheritanceRoot();
                 final String superType = inheritanceRootResource.getResourceSuperType();
-                if (superType == null) {
+
+                if (superType == null
+                       || roots.contains(inheritanceRootResource.getPath())) { // avoid inheritance
loops
                     currentTarget = null;
                 } else {
                     final String superTypeChildPath = superType + pathRelativeToInheritanceRoot;
@@ -81,6 +86,7 @@ public class OverridingResourcePicker implements MergedResourcePicker {
                         currentTarget = new StubResource(resolver, superTypeChildPath);
                     }
                     resources.add(currentTarget);
+                    roots.add(inheritanceRootResource.getPath());
                 }
             }
         }
diff --git a/src/test/java/org/apache/sling/resourcemerger/impl/OverridingResourceProviderTest.java
b/src/test/java/org/apache/sling/resourcemerger/impl/OverridingResourceProviderTest.java
index 7531002..8017f1f 100644
--- a/src/test/java/org/apache/sling/resourcemerger/impl/OverridingResourceProviderTest.java
+++ b/src/test/java/org/apache/sling/resourcemerger/impl/OverridingResourceProviderTest.java
@@ -62,6 +62,9 @@ public class OverridingResourceProviderTest {
      *
      * /apps/a/2 has the super type of /apps/a/1
      * /apps/a/3 has the super type of /apps/a/2
+     *
+     * /apps/a/4 has the super type of /apps/a/4/b/4
+     * /apps/x has the super type of x/y
      */
     @Before
     public void setup() throws Exception {
@@ -85,6 +88,13 @@ public class OverridingResourceProviderTest {
                     .resource("/apps/a/2").p(SUPER_TYPE, "a/1").p("b", "2").p(MergedResourceConstants.PN_HIDE_CHILDREN,
new String[] {"b"})
                     .resource("c").p("1", "c")
                     .resource("/apps/a/3").p(SUPER_TYPE, "a/2")
+                    .resource("/apps/a/4").p(SUPER_TYPE, "/apps/a/4/b/4")
+                    .resource("b")
+                    .resource("4")
+                    .resource("d")
+                    .resource("/apps/x").p(SUPER_TYPE, "x/y")
+                    .resource("y")
+                    .resource("z")
                     .commit();
 
         this.provider = new MergingResourceProvider("/override", new OverridingResourcePicker(),
false, true);
@@ -168,4 +178,14 @@ public class OverridingResourceProviderTest {
         assertNotNull(d1a);
     }
 
+    @Test
+    public void testLoopInInheritance() {
+        final Resource rsrcA4 = this.provider.getResource(this.resolver, "/override/apps/a/4");
+
+        Resource d = getChildResource(rsrcA4, "d");
+        assertNotNull(d);
+
+        final Resource z = this.provider.getResource(this.resolver, "/override/apps/x/z");
+        assertNotNull(z);
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message