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 70e3dd11679fa5188920e9785293091b81a840ea
Author: Robert Munteanu <[email protected]>
AuthorDate: Mon Aug 17 14:46:13 2020 +0200

    SLING-9623 - ResourceMapperImpl.getAllMappings is incomplete for nested 
alias
    
    Increase test coverage by adding a test for an empty path.
---
 .../impl/mapping/ResourceMapperImpl.java           |  3 ++-
 .../impl/mapping/ResourceMapperImplTest.java       | 22 ++++++++++++++++++++--
 2 files changed, 22 insertions(+), 3 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 1bd69b2..0cee1cd 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
@@ -141,7 +141,8 @@ public class ResourceMapperImpl implements ResourceMapper {
         ParsedParameters parsed = new ParsedParameters(mappedPath);
         
         // 2. add the requested path itself
-        mappings.add(mappedPath);
+        if ( !mappedPath.isEmpty() )
+            mappings.add(mappedPath);
 
         // 3. load mappings from the resource path
         populateMappingsFromMapEntries(mappings, 
Collections.singletonList(mappedPath), requestContext);
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 77f6ca2..6235213 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
@@ -150,6 +150,22 @@ public class ResourceMapperImplTest {
     }
     
     /**
+     * Validates that mappings for an empty return the root path
+     * 
+     * @throws LoginException
+     */
+    @Test
+    public void mapNonExistingEmptyPath() throws LoginException {
+        
+        ExpectedMappings.nonExistingResource("")
+            .singleMapping("/")
+            .singleMappingWithRequest("/app/")
+            .allMappings("/")
+            .allMappingsWithRequest("/app/")
+            .verify(resolver, req);
+    }
+    
+    /**
      * Validates that mappings for a non-existing resource only contain that 
resource's path
      * 
      * @throws LoginException
@@ -371,9 +387,11 @@ public class ResourceMapperImplTest {
             ResourceMapperImpl mapper = (ResourceMapperImpl) 
resolver.adaptTo(ResourceMapper.class);
             
             assertThat("Single mapping without request", 
mapper.getMapping(path), is(singleMapping));
-            assertThat("Single mapping with request", mapper.getMapping(path, 
request), is(singleMappingWithRequest));
+            if ( !path.isEmpty() ) // an empty path is invalid, hence not 
testing with a request
+                assertThat("Single mapping with request", 
mapper.getMapping(path, request), is(singleMappingWithRequest));
             assertThat("All mappings without request", 
mapper.getAllMappings(path), is(allMappings));
-            assertThat("All mappings with request", 
mapper.getAllMappings(path, request), is(allMappingsWithRequest));
+            if ( !path.isEmpty() ) // an empty path is invalid, hence not 
testing with a request
+                assertThat("All mappings with request", 
mapper.getAllMappings(path, request), is(allMappingsWithRequest));
         }
 
         private void checkConfigured() {

Reply via email to