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

rombert pushed a commit to annotated tag 
org.apache.sling.testing.resourceresolver-mock-1.1.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-resourceresolver-mock.git

commit e0f90a945357287d673936f6c1ad081f2db9fd75
Author: Stefan Seifert <[email protected]>
AuthorDate: Mon Oct 13 08:14:18 2014 +0000

    SLING-4038 Normalize path in getResource(String) method
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/testing/resourceresolver-mock@1631310
 13f79535-47bb-0310-9956-ffa450edef68
---
 .../testing/resourceresolver/MockResourceResolver.java    | 15 ++++++++-------
 .../resourceresolver/SlingCrudResourceResolverTest.java   |  9 +++++++++
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java
 
b/src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java
index 1c009e8..ea01646 100644
--- 
a/src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java
+++ 
b/src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java
@@ -143,25 +143,26 @@ public class MockResourceResolver extends SlingAdaptable 
implements ResourceReso
     }
     
     private Resource getResourceInternal(final String path) {
-        if ( path.startsWith("/") ) {
-            if ( this.deletedResources.contains(path) ) {
+        String normalizedPath = ResourceUtil.normalize(path);
+        if ( normalizedPath.startsWith("/") ) {
+            if ( this.deletedResources.contains(normalizedPath) ) {
                 return null;
             }
-            final Map<String, Object> tempProps = 
this.temporaryResources.get(path);
+            final Map<String, Object> tempProps = 
this.temporaryResources.get(normalizedPath);
             if ( tempProps != null ) {
-                final Resource rsrc = new MockResource(path, tempProps, this);
+                final Resource rsrc = new MockResource(normalizedPath, 
tempProps, this);
                 return rsrc;
             }
             synchronized ( this.resources ) {
-                final Map<String, Object> props = this.resources.get(path);
+                final Map<String, Object> props = 
this.resources.get(normalizedPath);
                 if ( props != null ) {
-                    final Resource rsrc = new MockResource(path, props, this);
+                    final Resource rsrc = new MockResource(normalizedPath, 
props, this);
                     return rsrc;
                 }
             }
         } else {
             for(final String s : this.getSearchPath() ) {
-                final Resource rsrc = this.getResource(s + '/' + path);
+                final Resource rsrc = this.getResource(s + '/' + 
normalizedPath);
                 if ( rsrc != null ) {
                     return rsrc;
                 }
diff --git 
a/src/test/java/org/apache/sling/testing/resourceresolver/SlingCrudResourceResolverTest.java
 
b/src/test/java/org/apache/sling/testing/resourceresolver/SlingCrudResourceResolverTest.java
index 44e48d4..6893cf5 100644
--- 
a/src/test/java/org/apache/sling/testing/resourceresolver/SlingCrudResourceResolverTest.java
+++ 
b/src/test/java/org/apache/sling/testing/resourceresolver/SlingCrudResourceResolverTest.java
@@ -168,4 +168,13 @@ public class SlingCrudResourceResolverTest {
         assertEquals(NT_UNSTRUCTURED, resource1.getResourceType());
     }
 
+    @Test
+    public void testNormalizePath() throws PersistenceException {
+        Resource resource1 = resourceResolver.getResource(testRoot.getPath() + 
"/./node1");
+        assertEquals("node1", resource1.getName());
+
+        Resource resource11 = resourceResolver.getResource(testRoot.getPath() 
+ "/node1/../node1/node11");
+        assertEquals("node11", resource11.getName());
+    }
+
 }

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to