[ 
https://issues.apache.org/jira/browse/SLING-6501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16225213#comment-16225213
 ] 

ASF GitHub Bot commented on SLING-6501:
---------------------------------------

cziegeler closed pull request #1: SLING-6501:Incorrect normalization of path of 
an asset with name begi…
URL: https://github.com/apache/sling-org-apache-sling-api/pull/1
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/main/java/org/apache/sling/api/resource/ResourceUtil.java 
b/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
index 134e133..02d4739 100644
--- a/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
+++ b/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
@@ -82,7 +82,7 @@
 
                 lastSlash = bufIdx;
                 numDots = 0;
-            } else if (c == '.' && numDots < 2) {
+            } else if (c == '.' && useDot(buf, bufIdx) && numDots < 2) {
                 numDots++;
             } else {
                 // find the next slash
@@ -118,6 +118,21 @@
         return resolved;
     }
 
+    // use this dot only if followed by /
+    // don't use if followed by neither . nor /
+    // keep checking till a non-dot is found
+    private static boolean useDot(char[] buf, int bufIdx) {
+        while(bufIdx < buf.length -1) {
+            if(buf[bufIdx] == '/') {
+                return true;
+            }
+            else if(buf[bufIdx] != '.') {
+                return false;
+            }
+            bufIdx++;
+        }
+        return true;
+    }
     /**
      * Utility method returns the parent path of the given <code>path</code>,
      * which is normalized by {@link #normalize(String)} before resolving the
diff --git a/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java 
b/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
index 3688ac0..3e8ca08 100644
--- a/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
+++ b/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
@@ -114,6 +114,12 @@
         assertEquals("/az/...", ResourceUtil.normalize("/az/..."));
         assertEquals("/az/bz/...", ResourceUtil.normalize("/az/bz/..."));
 
+        
assertEquals("/content/dam/jpg_folder/.jpg/jcr:content/metadata/dc:title",
+                
ResourceUtil.normalize("/content/dam/./jpg_folder/.jpg/jcr:content/metadata/dc:title"));
+
+        
assertEquals("/content/dam/jpg_folder/....jpg/jcr:content/metadata/dc:title",
+                
ResourceUtil.normalize("/content/dam/./jpg_folder/....jpg/jcr:content/metadata/dc:title"));
+
         try {
             ResourceUtil.normalize(null);
             fail("Resolving null expects NullPointerException");


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Incorrect normalization of path of an asset with name beginning with '.'
> ------------------------------------------------------------------------
>
>                 Key: SLING-6501
>                 URL: https://issues.apache.org/jira/browse/SLING-6501
>             Project: Sling
>          Issue Type: Bug
>          Components: API
>            Reporter: Gaurav Gupta
>            Priority: Critical
>             Fix For: API 2.16.4
>
>
> When a new asset named ".jpg" is being modified in JCR, 
> [ResourceUtil.normalize()|https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ResourceUtil.html#normalize-java.lang.String-]
>  method returns an incorrect normalized path which leads to the creation of a 
> folder named '.jp' under the same parent node. A small test shows this 
> anomaly.
> {code:java}
> public class RUNormalizeTest {
>       public static String toPropertyPath(String paramName, String path) {
>         if (!paramName.startsWith("/")) {
>             paramName = ResourceUtil.normalize(path + '/' + paramName);
>         }
>         return paramName;
>     }
>       
>       public static void main(String[] args) {
>               String pName = 
> "./jpg_folder/.jpg/jcr:content/metadata/dc:title";
>               String path = "/content/dam";
>               System.out.println(toPropertyPath(pName,path));
>       }
> }
> {code}
> Expected output: /content/dam/jpg_folder/.jpg/jcr:content/metadata/dc:title 
> Output: /content/dam/jpg_folder/.jp/jcr:content/metadata/dc:title
> In the above code, the properties of an asset named '.jpg' are being 
> modified. However, the normalize method returns an incorrect path for the 
> input path.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to