You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2006/08/15 03:17:06 UTC

svn commit: r431478 - in /tapestry/tapestry4/trunk/tapestry-framework/src: java/org/apache/tapestry/asset/AssetService.java test/org/apache/tapestry/asset/TestUnprotectedAsset.java

Author: jkuhnert
Date: Mon Aug 14 18:17:06 2006
New Revision: 431478

URL: http://svn.apache.org/viewvc?rev=431478&view=rev
Log:
Applied Ben Sommervilles patch from TAPESTRY-1061 to fix a bug in css path translations when grabbing resources
from jar files.

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java?rev=431478&r1=431477&r2=431478&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java Mon Aug 14 18:17:06 2006
@@ -275,24 +275,41 @@
      */
     String translatePath(String path)
     {
-        if (path == null) return null;
+        if (path == null) 
+            return null;
+
+        String tpath = translateCssPath(path);
         
-        String ret = FilenameUtils.normalize(path);
+        String ret = FilenameUtils.normalize(tpath);
         ret = FilenameUtils.separatorsToUnix(ret);
         
+        return ret;
+    }
+    
+    /**
+     * Fixes any paths containing .css extension relative references.
+     * 
+     * @param path The path to fix.
+     * @return The absolute path to the resource referenced in the path. (if any)
+     */
+    private String translateCssPath(String path) {
+        
         // don't parse out actual css files
-        if (ret.endsWith(".css")) return ret;
+        if (path.endsWith(".css")) 
+            return path;
         
-        int index = ret.lastIndexOf(".css");
-        if (index <= -1) return ret;
+        int index = path.lastIndexOf(".css");
+        if (index <= -1) 
+            return path;
         
         // now need to parse out whatever css file was referenced to get the real path
-        int pathEnd = ret.lastIndexOf("/", index);
-        if (pathEnd <= -1) return ret;
+        int pathEnd = path.lastIndexOf("/", index);
+        if (pathEnd <= -1) 
+            return path;
         
-        return ret.substring(0, pathEnd + 1) + ret.substring(index + 4, ret.length());
+        return path.substring(0, pathEnd + 1) + path.substring(index + 4, path.length());
     }
-    
+
     /**
      * Checks if the resource contained within the specified URL 
      * has a modified time greater than the request header value
@@ -307,7 +324,8 @@
     boolean cachedResource(URL resourceURL)
     {
         File resource = new File(resourceURL.getFile());
-        if (!resource.exists()) return false;
+        if (!resource.exists()) 
+            return false;
         
         //even if it doesn't exist in header the value will be -1, 
         //which means we need to write out the contents of the resource

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java?rev=431478&r1=431477&r2=431478&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java Mon Aug 14 18:17:06 2006
@@ -53,7 +53,7 @@
     /**
      * Tests for regexp patterns describing unprotected resources.
      */
-    public void testUnProtectedMatch()
+    public void test_Protected_Pattern_Match()
     {
         Pattern pr = newPattern("org/apache/tapestry/asset/.*.txt");
         
@@ -88,7 +88,7 @@
      * Tests and asserts that it doesn't take ~longer~ to work with undigested
      * resources using patterns than normal digested resources.
      */
-    public void testResourcePerformanceComparison()
+    public void test_Resource_Performance_Comparison()
     {
         Pattern pr = newPattern("/org/apache/tapestry/asset/tapestry-in-action.png");
 
@@ -116,7 +116,7 @@
     /**
      * Tests new path ordering encoding.
      */
-    public void testPathComparator()
+    public void test_Path_Comparator()
     {
         Map parameters = new TreeMap(new AssetComparator());
         
@@ -138,7 +138,7 @@
     /**
      * Tests the implementation of {@link ResourceMatcher}.
      */
-    public void testResourceMatcher()
+    public void test_Resource_Matcher()
     {
         ResourceMatcherImpl rm = new ResourceMatcherImpl();
         List patterns = new ArrayList();
@@ -163,9 +163,10 @@
         assertTrue(rm.containsResource("/org/apache/tapestry/html/dojo/src/test.png"));
     }
     
-    public void testCssPaths()
+    public void test_Css_Paths()
     {
         AssetService service = new AssetService();
+        
         String path = "/dojo/src/widget/template/HtmlComboBox.cssimages/foo.gif";
         
         assertEquals("/dojo/src/widget/template/images/foo.gif", service.translatePath(path));
@@ -177,7 +178,39 @@
                 service.translatePath("/things/mytemplate.css"));
         assertNull(service.translatePath(null));
     }
-    
+
+    public void test_Relative_Paths()
+    {
+        AssetService service = new AssetService();
+        
+        assertEquals("/src", service.translatePath("/dojo/../src"));
+        assertEquals("src", service.translatePath("dojo/../src"));
+        assertEquals("/src", service.translatePath("/dojo/blah/../../src"));
+        assertEquals("src", service.translatePath("dojo/blah/../../src"));
+        assertEquals("/src", service.translatePath("/dojo/../blah/../src"));
+        assertEquals("src", service.translatePath("dojo/../blah/../src"));
+        assertEquals("/src/", service.translatePath("/dojo/../src/"));
+        assertEquals("src/", service.translatePath("dojo/../src/"));
+        assertEquals("/", service.translatePath("/dojo/../"));
+        assertEquals("", service.translatePath("dojo/../"));
+    }     
+
+    public void test_Relative_Css_Paths()
+    {
+        AssetService service = new AssetService();
+        
+        String path = "/dojo/src/widget/template/HtmlComboBox.css../images/foo.gif";
+        
+        assertEquals("/dojo/src/widget/images/foo.gif", service.translatePath(path));
+
+        path = "/dojo/src/widget/template/HtmlComboBox.css../../images/foo.gif";
+        assertEquals("/dojo/src/images/foo.gif", service.translatePath(path));
+
+        assertEquals("/boo/things/",
+                service.translatePath("/boo/templates/somethingdumb.css../things/"));
+    }
+
+
     public void test_Resource_Link_Paths()
     {
         LinkFactory factory = newMock(LinkFactory.class);