Author: markt
Date: Thu May 31 20:42:38 2012
New Revision: 1344902

URL: http://svn.apache.org/viewvc?rev=1344902&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53257
BZ 53257 is partially a regression caused by r1152593 (the fix for BZ 51584) 
and partially an existing issue that had always been present.
This patch:
- reverts r1152593
- extends the test cases to cover BZ 53257 & BZ 51584
- correctly fixes BZ 53257 & BZ 51584
- fixes the additional issues the unit tests uncovered

Added:
    
tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestApplicationContext.java
      - copied unchanged from r1344868, 
tomcat/trunk/test/org/apache/catalina/core/TestApplicationContext.java
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/
      - copied from r1344868, tomcat/trunk/test/webapp-3.0/bug53257/
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo#bar.jsp
      - copied unchanged from r1344893, 
tomcat/trunk/test/webapp-3.0/bug53257/foo#bar.jsp
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo#bar.txt
      - copied unchanged from r1344890, 
tomcat/trunk/test/webapp-3.0/bug53257/foo#bar.txt
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo%bar.jsp
      - copied unchanged from r1344893, 
tomcat/trunk/test/webapp-3.0/bug53257/foo%bar.jsp
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo%bar.txt
      - copied unchanged from r1344893, 
tomcat/trunk/test/webapp-3.0/bug53257/foo%bar.txt
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo&bar.jsp
      - copied unchanged from r1344893, 
tomcat/trunk/test/webapp-3.0/bug53257/foo&bar.jsp
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo&bar.txt
      - copied unchanged from r1344890, 
tomcat/trunk/test/webapp-3.0/bug53257/foo&bar.txt
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo+bar.jsp
      - copied unchanged from r1344893, 
tomcat/trunk/test/webapp-3.0/bug53257/foo+bar.jsp
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo+bar.txt
      - copied unchanged from r1344890, 
tomcat/trunk/test/webapp-3.0/bug53257/foo+bar.txt
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo;bar.jsp
      - copied unchanged from r1344893, 
tomcat/trunk/test/webapp-3.0/bug53257/foo;bar.jsp
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo;bar.txt
      - copied unchanged from r1344890, 
tomcat/trunk/test/webapp-3.0/bug53257/foo;bar.txt
Removed:
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo#bar
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo&bar
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo+bar
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/foo;bar
Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java
    
tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/DirContextURLConnection.java
    tomcat/tc7.0.x/trunk/res/checkstyle/org-import-control.xml
    tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestCompiler.java
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/index.jsp
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1344868,1344890,1344893,1344896,1344901

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1344902&r1=1344901&r2=1344902&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java 
Thu May 31 20:42:38 2012
@@ -14,14 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.catalina.core;
 
-
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -69,7 +67,6 @@ import org.apache.catalina.connector.Con
 import org.apache.catalina.deploy.FilterDef;
 import org.apache.catalina.util.ResourceSet;
 import org.apache.catalina.util.ServerInfo;
-import org.apache.naming.resources.DirContextURLStreamHandler;
 import org.apache.naming.resources.Resource;
 import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.buf.CharChunk;
@@ -536,9 +533,8 @@ public class ApplicationContext
             String hostName = context.getParent().getName();
             try {
                 resources.lookup(normPath);
-                return new URL
-                    ("jndi", "", 0, getJNDIUri(hostName, fullPath),
-                     new DirContextURLStreamHandler(resources));
+                return new URI("jndi",
+                        getJNDIUri(hostName, fullPath), null).toURL();
             } catch (NamingException e) {
                 // Ignore
             } catch (Exception e) {

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/DirContextURLConnection.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/DirContextURLConnection.java?rev=1344902&r1=1344901&r2=1344902&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/DirContextURLConnection.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/naming/resources/DirContextURLConnection.java
 Thu May 31 20:42:38 2012
@@ -22,8 +22,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
 import java.security.Permission;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -42,6 +40,8 @@ import javax.naming.directory.Attributes
 import javax.naming.directory.DirContext;
 
 import org.apache.naming.JndiPermission;
+import org.apache.tomcat.util.buf.UDecoder;
+import org.apache.tomcat.util.buf.UEncoder;
 import org.apache.tomcat.util.http.FastHttpDateFormat;
 
 /**
@@ -55,13 +55,17 @@ import org.apache.tomcat.util.http.FastH
  * @author <a href="mailto:[email protected]";>Remy Maucherat</a>
  * @version $Revision$
  */
-public class DirContextURLConnection 
-    extends URLConnection {
-    
-    
+public class DirContextURLConnection extends URLConnection {
+
+    private static final UDecoder URL_DECODER = new UDecoder();
+    private static final UEncoder URL_ENCODER = new UEncoder();
+
+    static{
+        URL_ENCODER.addSafeCharacter('/');
+    }
+
     // ----------------------------------------------------------- Constructors
     
-    
     public DirContextURLConnection(DirContext context, URL url) {
         super(url);
         if (context == null)
@@ -120,8 +124,8 @@ public class DirContextURLConnection 
 
 
     // ------------------------------------------------------------- Properties
-    
-    
+
+
     /**
      * Connect to the DirContext, and retrieve the bound object, as well as
      * its attributes. If no object is bound with the name specified in the
@@ -155,7 +159,7 @@ public class DirContextURLConnection 
                         path = path.substring(contextPath.length());
                     }
                 }
-                path = URLDecoder.decode(path, "UTF-8");
+                path = URL_DECODER.convert(path, false);
                 object = context.lookup(path);
                 attributes = context.getAttributes(path);
                 if (object instanceof Resource)
@@ -389,7 +393,7 @@ public class DirContextURLConnection 
         // Reopen resource
         try {
             resource = (Resource) context.lookup(
-                    URLDecoder.decode(getURL().getFile(), "UTF-8"));
+                    URL_DECODER.convert(getURL().getFile(), false));
         } catch (NamingException e) {
             // Ignore
         }
@@ -455,8 +459,7 @@ public class DirContextURLConnection 
                     context.list(file.substring(start));
                 while (enumeration.hasMoreElements()) {
                     NameClassPair ncp = enumeration.nextElement();
-                    result.addElement(
-                            URLEncoder.encode(ncp.getName(), "UTF-8"));
+                    result.addElement(URL_ENCODER.encodeURL(ncp.getName()));
                 }
             } catch (NamingException e) {
                 // Unexpected exception

Modified: tomcat/tc7.0.x/trunk/res/checkstyle/org-import-control.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/res/checkstyle/org-import-control.xml?rev=1344902&r1=1344901&r2=1344902&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/res/checkstyle/org-import-control.xml (original)
+++ tomcat/tc7.0.x/trunk/res/checkstyle/org-import-control.xml Thu May 31 
20:42:38 2012
@@ -105,6 +105,8 @@
     <allow pkg="javax.mail"/>
     <allow pkg="javax.wsdl"/>
     <allow pkg="org.apache.naming"/>
+    <allow class="org.apache.tomcat.util.buf.UDecoder"/>
+    <allow class="org.apache.tomcat.util.buf.UEncoder"/>
     <allow class="org.apache.tomcat.util.http.FastHttpDateFormat"/>
     <allow class="org.apache.tomcat.util.http.RequestUtil"/>
     <subpackage name="factory.webservices">

Modified: tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestCompiler.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestCompiler.java?rev=1344902&r1=1344901&r2=1344902&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestCompiler.java 
(original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestCompiler.java Thu 
May 31 20:42:38 2012
@@ -76,8 +76,101 @@ public class TestCompiler extends Tomcat
         
assertTrue(headers.get("Content-Type").get(0).startsWith("text/plain"));
     }
 
+    @Test
+    public void testBug53257a() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp-3.0");
+        tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+        tomcat.start();
+
+        ByteChunk res = getUrl("http://localhost:"; + getPort() +
+                "/test/bug53257/foo%3bbar.jsp");
+
+        // Check request completed
+        String result = res.toString();
+        assertEcho(result, "OK");
+    }
+
+    @Test
+    public void testBug53257b() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp-3.0");
+        tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+        tomcat.start();
+
+        ByteChunk res = getUrl("http://localhost:"; + getPort() +
+                "/test/bug53257/foo&bar.jsp");
+
+        // Check request completed
+        String result = res.toString();
+        assertEcho(result, "OK");
+    }
+
+    @Test
+    public void testBug53257c() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp-3.0");
+        tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+        tomcat.start();
+
+        ByteChunk res = getUrl("http://localhost:"; + getPort() +
+                "/test/bug53257/foo%23bar.jsp");
+
+        // Check request completed
+        String result = res.toString();
+        assertEcho(result, "OK");
+    }
+
+    @Test
+    public void testBug53257d() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp-3.0");
+        tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+        tomcat.start();
+
+        ByteChunk res = getUrl("http://localhost:"; + getPort() +
+                "/test/bug53257/foo%25bar.jsp");
+
+        // Check request completed
+        String result = res.toString();
+        assertEcho(result, "OK");
+    }
+
+    @Test
+    public void testBug53257e() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp-3.0");
+        tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+        tomcat.start();
+
+        ByteChunk res = getUrl("http://localhost:"; + getPort() +
+                "/test/bug53257/foo+bar.jsp");
+
+        // Check request completed
+        String result = res.toString();
+        assertEcho(result, "OK");
+    }
+
+    @Test
+    public void testBug51584() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp-3.0-fragments");
+        tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+        tomcat.start();
+
+        // No further tests required. The bug triggers an infinite loop on
+        // context start so the test will crash before it reaches this point if
+        // it fails
+    }
+
     /** Assertion for text printed by tags:echo */
     private static void assertEcho(String result, String expected) {
-        assertTrue(result.indexOf("<p>" + expected + "</p>") > 0);
+        assertTrue(result, result.indexOf("<p>" + expected + "</p>") > 0);
     }
 }

Modified: tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/index.jsp
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/index.jsp?rev=1344902&r1=1344868&r2=1344902&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/index.jsp (original)
+++ tomcat/tc7.0.x/trunk/test/webapp-3.0/bug53257/index.jsp Thu May 31 20:42:38 
2012
@@ -15,8 +15,8 @@
   limitations under the License.
 --%><%@page contentType="text/plain; charset=UTF-8"
 %><%@page import="java.net.URL,java.net.URLConnection"%><%
-    String[] testFiles =
-            new String[] {"foo;bar", "foo&bar", "foo#bar", "foo+bar"};
+    String[] testFiles = new String[] {"foo;bar.txt", "foo&bar.txt",
+            "foo#bar.txt", "foo%bar.txt", "foo+bar.txt"};
     for (String testFile : testFiles) {
         URL url = application.getResource("/bug53257/" + testFile);
         if (url == null) {

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1344902&r1=1344901&r2=1344902&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu May 31 20:42:38 2012
@@ -146,6 +146,16 @@
         <code>JreMemoryLeakPreventionListener</code>. (markt)
       </fix>
       <fix>
+        <bug>53257</bug>: Ensure that resources, inclusing JSP files, that have
+        names that include characters with special meanings in URLs (such as
+        ampersand, semicolon, plus, hash and percent) are correctly handled.
+        This bug is partially a regression caused by the original fix for
+        <bug>51584</bug> and partially an existing issue that had not 
previously
+        been identified. This fix reverts the original fix for 
<bug>51584</bug>,
+        correctly fixes that issue and fixes the additional issues identified 
by
+        the test cases that were also added as part of this fix. (markt)
+      </fix>
+      <fix>
         <bug>53267</bug>: Ensure that using the GC Daemon Protection feature of
         the <code>JreMemoryLeakPreventionListener</code> does not trigger a
         full GC every hour. (markt)



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to