incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1202102 - /sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/CompilerUtil.java
Date Tue, 15 Nov 2011 09:10:52 GMT
Author: cziegeler
Date: Tue Nov 15 09:10:51 2011
New Revision: 1202102

URL: http://svn.apache.org/viewvc?rev=1202102&view=rev
Log:
SLING-2282 : Java Script Engine does not escape directory paths

Modified:
    sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/CompilerUtil.java

Modified: sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/CompilerUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/CompilerUtil.java?rev=1202102&r1=1202101&r2=1202102&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/CompilerUtil.java
(original)
+++ sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/CompilerUtil.java
Tue Nov 15 09:10:51 2011
@@ -30,11 +30,22 @@ public class CompilerUtil {
         } else {
             str = path;
         }
-        final int pos = str.lastIndexOf("/");
-        if ( pos == -1 ) {
-            return makeJavaIdentifier(str);
+        final StringBuilder sb = new StringBuilder();
+        int pos = 0;
+        int start = 0;
+        while ( pos < str.length() ) {
+            final char c = str.charAt(pos);
+            if ( c == '/' ) {
+                if ( start != pos ) {
+                    sb.append(makeJavaIdentifier(str.substring(start, pos)));
+                }
+                sb.append(c);
+                start = pos + 1;
+            }
+            pos++;
         }
-        return str.substring(0, pos + 1) + makeJavaIdentifier(str.substring(pos + 1));
+        sb.append(makeJavaIdentifier(str.substring(start)));
+        return sb.toString();
     }
 
     /**



Mime
View raw message