You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/01/09 21:44:38 UTC

svn commit: r610558 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/internal/services/RequestPathOptimizerImpl.java test/java/org/apache/tapestry/internal/services/RequestPathOptimizerImplTest.java

Author: hlship
Date: Wed Jan  9 12:44:33 2008
New Revision: 610558

URL: http://svn.apache.org/viewvc?rev=610558&view=rev
Log:
TAPESTRY-2033: Optimized requests paths are broken for root paths within contexts

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RequestPathOptimizerImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RequestPathOptimizerImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RequestPathOptimizerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RequestPathOptimizerImpl.java?rev=610558&r1=610557&r2=610558&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RequestPathOptimizerImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/RequestPathOptimizerImpl.java Wed Jan  9 12:44:33 2008
@@ -46,14 +46,23 @@
     {
         if (_forceFull || _request.isXHR()) return path;
 
+        String requestPath = _request.getPath();
+
         StringBuilder builder = new StringBuilder();
 
         builder.append(_request.getContextPath());
-        builder.append(_request.getPath());
+
+
+        builder.append(requestPath);
 
         String requestURI = builder.toString();
 
         String[] requestTerms = SLASH_PATTERN.split(requestURI);
+
+        // Degenerate case when getting the root application
+
+        if (requestPath.equals("")) requestTerms = add(requestTerms, "");
+
         String[] pathTerms = SLASH_PATTERN.split(path);
 
         builder.setLength(0);
@@ -95,5 +104,15 @@
         // path.
 
         return path;
+    }
+
+    private String[] add(String[] array, String s)
+    {
+        String[] newArray = new String[array.length + 1];
+
+        System.arraycopy(array, 0, newArray, 0, array.length);
+        newArray[array.length] = s;
+
+        return newArray;
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RequestPathOptimizerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RequestPathOptimizerImplTest.java?rev=610558&r1=610557&r2=610558&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RequestPathOptimizerImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/RequestPathOptimizerImplTest.java Wed Jan  9 12:44:33 2008
@@ -24,27 +24,44 @@
     @DataProvider(name = "uri_optimization")
     public Object[][] uri_optimization_data()
     {
-        return new Object[][]{
+        return new Object[][]{{"/context", "/foo/bar.png", "/context/foo/baz.png", "baz.png"},
 
-                {"/context", "/foo/bar", "foo/baz", "baz"},
+                              {"/context", "/foo/bar.gif", "/context/foo//baz.gif", "baz.gif"},
 
-                {"/context", "/foo/bar", "foo//baz", "baz"},
+                              {"/context", "/foo//bar.css", "/context/foo/baz.css", "baz.css"},
 
-                {"/context", "/foo//bar", "foo/baz", "baz"},
+                              {"", "/foo/bar.css", "/foo/baz.css", "baz.css"},
 
-                {"", "/foo/bar", "foo/baz", "baz"},
+                              {"/reallylongcontexttoensureitisrelative", "/foo/bar/baz/biff.gif",
+                               "/reallylongcontexttoensureitisrelative/gnip/gnop.gif", "../../../gnip/gnop.gif"},
 
-                {"/reallylongcontexttoensureitisrelative", "/foo/bar/baz/biff", "gnip/gnop", "../../../gnip/gnop"},
+                              {"", "/foo/bar/baz/biff/yepthisissolongthatabsoluteurlisshorter/dude", "/gnip/gnop",
+                               "/gnip/gnop"},
 
-                {"", "/foo/bar/baz/biff/yepthisissolongthatabsoluteurlisshorter/dude", "gnip/gnop", "/gnip/gnop"},
+                              {"", "/foo/bar", "/foo/bar/baz/bif", "bar/baz/bif"},
 
-                {"", "/foo/bar", "/foo/bar/baz/bif", "bar/baz/bif"},
+                              {"", "/foo/bar/baz/bif", "/foo", "/foo"},
 
-                {"", "/foo/bar/baz/bif", "foo", "/foo"},
+                              {"/ctx", "/foo/bar/baz/bif", "/ctx/foo", "/ctx/foo"},
 
-                {"/ctx", "/foo/bar/baz/bif", "foo", "/ctx/foo"},
+                              {"/anotherobnoxiouslylongcontextthatiwllforcerelative", "/foo/bar/baz/bif",
+                               "/anotherobnoxiouslylongcontextthatiwllforcerelative/foo", "../../../foo"},
 
-                {"/anotherobnoxiouslylongcontextthatiwllforcerelative", "/foo/bar/baz/bif", "foo", "../../../foo"}
+                              // A couple of better examples, see TAPESTRY-2033
+
+                              {"/manager", "", "/manager/asset/foo.gif", "asset/foo.gif"},
+
+                              {"", "", "/asset/foo.gif", "asset/foo.gif"},
+
+                              {"/verylongcontextname", "/style/app.css", "/verylongcontextname/asset/foo.gif",
+                               "../asset/foo.gif"},
+
+                              {"", "/eventhandlerdemo.barney/one", "/eventhandlerdemo.clear/anything",
+                               "/eventhandlerdemo.clear/anything"},
+
+                              {"/verylongcontextname", "/eventhandlerdemo.barney/one",
+                               "/verylongcontextname/eventhandlerdemo.clear/anything",
+                               "../eventhandlerdemo.clear/anything"}
 
         };
     }
@@ -59,12 +76,11 @@
         train_getContextPath(request, contextPath);
         train_getPath(request, requestPath);
 
-
         replay();
 
         RequestPathOptimizer optimizer = new RequestPathOptimizerImpl(request, false);
 
-        assertEquals(optimizer.optimizePath(expectedURI), expectedURI);
+        assertEquals(optimizer.optimizePath(path), expectedURI);
 
         verify();
     }