incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r633008 - in /incubator/sling/trunk/sling/servlets-default/src: main/java/org/apache/sling/servlets/RedirectServlet.java test/java/org/apache/sling/servlets/RedirectServletTest.java
Date Mon, 03 Mar 2008 09:45:56 GMT
Author: fmeschbe
Date: Mon Mar  3 01:45:56 2008
New Revision: 633008

URL: http://svn.apache.org/viewvc?rev=633008&view=rev
Log:
SLING-300 Do not compare the last element of the base path to the
target path to prevent going up to high.

Modified:
    incubator/sling/trunk/sling/servlets-default/src/main/java/org/apache/sling/servlets/RedirectServlet.java
    incubator/sling/trunk/sling/servlets-default/src/test/java/org/apache/sling/servlets/RedirectServletTest.java

Modified: incubator/sling/trunk/sling/servlets-default/src/main/java/org/apache/sling/servlets/RedirectServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlets-default/src/main/java/org/apache/sling/servlets/RedirectServlet.java?rev=633008&r1=633007&r2=633008&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlets-default/src/main/java/org/apache/sling/servlets/RedirectServlet.java
(original)
+++ incubator/sling/trunk/sling/servlets-default/src/main/java/org/apache/sling/servlets/RedirectServlet.java
Mon Mar  3 01:45:56 2008
@@ -51,7 +51,7 @@
  * sent where the target is the relative URL from the current resource to the
  * target resource. Selectors, extension, suffix and query string are also
  * appended to the redirect URL.
- *
+ * 
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.component immediate="true" metatype="false"
  * @scr.property name="service.description" value="Request Redirect Servlet"
@@ -139,9 +139,8 @@
             postFix = null;
         }
 
-
         String basePath = request.getResource().getPath();
-        
+
         // make sure the target path is absolute
         if (!targetPath.startsWith("/")) {
             if (!basePath.endsWith("/")) {
@@ -149,7 +148,7 @@
             }
             targetPath = basePath.concat(targetPath);
         }
-        
+
         // append optional selectors etc.to the base path
         if (postFix != null) {
             basePath = basePath.concat(postFix);
@@ -157,7 +156,6 @@
 
         StringBuffer pathBuf = new StringBuffer();
 
-
         makeRelative(pathBuf, basePath, targetPath);
 
         if (postFix != null) {
@@ -183,7 +181,7 @@
 
         // find first non-matching part
         int off;
-        for (off = 0; off < bParts.length && off < tParts.length
+        for (off = 0; off < (bParts.length - 1) && off < tParts.length
             && bParts[off].equals(tParts[off]); off++);
 
         for (int i = bParts.length - off; i > 1; i--) {

Modified: incubator/sling/trunk/sling/servlets-default/src/test/java/org/apache/sling/servlets/RedirectServletTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlets-default/src/test/java/org/apache/sling/servlets/RedirectServletTest.java?rev=633008&r1=633007&r2=633008&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlets-default/src/test/java/org/apache/sling/servlets/RedirectServletTest.java
(original)
+++ incubator/sling/trunk/sling/servlets-default/src/test/java/org/apache/sling/servlets/RedirectServletTest.java
Mon Mar  3 01:45:56 2008
@@ -44,6 +44,32 @@
         assertEquals("../x/y", toRedirect(base, target));
     }
 
+    public void testChild() {
+        String base = "/a.html";
+        String target = "/a/b.html";
+        assertEquals("a/b.html", toRedirect(base, target));
+        
+        base = "/a";
+        target = "/a/b.html";
+        assertEquals("a/b.html", toRedirect(base, target));
+
+        base = "/a";
+        target = "/a/b";
+        assertEquals("a/b", toRedirect(base, target));
+        
+        base = "/a.html";
+        target = "/a/b/c.html";
+        assertEquals("a/b/c.html", toRedirect(base, target));
+        
+        base = "/a";
+        target = "/a/b/c.html";
+        assertEquals("a/b/c.html", toRedirect(base, target));
+
+        base = "/a";
+        target = "/a/b/c";
+        assertEquals("a/b/c", toRedirect(base, target));
+    }
+    
     public void testUnCommon() {
         String base = "/a/b/c/d";
         String target = "/w/x/y/z";



Mime
View raw message