You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/05/31 22:18:50 UTC

svn commit: r1344890 - in /tomcat/trunk: java/org/apache/catalina/core/ java/org/apache/naming/resources/ res/checkstyle/ test/org/apache/jasper/compiler/ test/webapp-3.0/bug53257/

Author: markt
Date: Thu May 31 20:18:49 2012
New Revision: 1344890

URL: http://svn.apache.org/viewvc?rev=1344890&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/trunk/test/webapp-3.0/bug53257/foo#bar.txt
      - copied unchanged from r1344868, tomcat/trunk/test/webapp-3.0/bug53257/foo#bar
    tomcat/trunk/test/webapp-3.0/bug53257/foo&bar.txt
      - copied unchanged from r1344868, tomcat/trunk/test/webapp-3.0/bug53257/foo&bar
    tomcat/trunk/test/webapp-3.0/bug53257/foo+bar.txt
      - copied unchanged from r1344868, tomcat/trunk/test/webapp-3.0/bug53257/foo+bar
    tomcat/trunk/test/webapp-3.0/bug53257/foo;bar.txt
      - copied unchanged from r1344868, tomcat/trunk/test/webapp-3.0/bug53257/foo;bar
Removed:
    tomcat/trunk/test/webapp-3.0/bug53257/foo#bar
    tomcat/trunk/test/webapp-3.0/bug53257/foo&bar
    tomcat/trunk/test/webapp-3.0/bug53257/foo+bar
    tomcat/trunk/test/webapp-3.0/bug53257/foo;bar
Modified:
    tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
    tomcat/trunk/java/org/apache/naming/resources/DirContextURLConnection.java
    tomcat/trunk/res/checkstyle/org-import-control.xml
    tomcat/trunk/test/org/apache/jasper/compiler/TestCompiler.java
    tomcat/trunk/test/webapp-3.0/bug53257/index.jsp

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1344890&r1=1344889&r2=1344890&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Thu May 31 20:18:49 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;
@@ -520,9 +517,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/trunk/java/org/apache/naming/resources/DirContextURLConnection.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/resources/DirContextURLConnection.java?rev=1344890&r1=1344889&r2=1344890&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/naming/resources/DirContextURLConnection.java (original)
+++ tomcat/trunk/java/org/apache/naming/resources/DirContextURLConnection.java Thu May 31 20:18:49 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,7 @@ 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.http.FastHttpDateFormat;
 
 /**
@@ -55,8 +54,9 @@ import org.apache.tomcat.util.http.FastH
  * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  * @version $Revision$
  */
-public class DirContextURLConnection
-    extends URLConnection {
+public class DirContextURLConnection extends URLConnection {
+
+    private static final UDecoder URL_DECODER = new UDecoder();
 
 
     // ----------------------------------------------------------- Constructors
@@ -123,7 +123,6 @@ 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
@@ -157,7 +156,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)
@@ -390,8 +389,7 @@ public class DirContextURLConnection
 
         // Reopen resource
         try {
-            resource = (Resource) context.lookup(
-                    URLDecoder.decode(getURL().getFile(), "UTF-8"));
+            resource = (Resource) context.lookup(getURL().getFile());
         } catch (NamingException e) {
             // Ignore
         }
@@ -457,8 +455,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(ncp.getName());
                 }
             } catch (NamingException e) {
                 // Unexpected exception

Modified: tomcat/trunk/res/checkstyle/org-import-control.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/res/checkstyle/org-import-control.xml?rev=1344890&r1=1344889&r2=1344890&view=diff
==============================================================================
--- tomcat/trunk/res/checkstyle/org-import-control.xml (original)
+++ tomcat/trunk/res/checkstyle/org-import-control.xml Thu May 31 20:18:49 2012
@@ -106,6 +106,7 @@
     <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.http.FastHttpDateFormat"/>
     <allow class="org.apache.tomcat.util.http.RequestUtil"/>
     <subpackage name="factory.webservices">

Modified: tomcat/trunk/test/org/apache/jasper/compiler/TestCompiler.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TestCompiler.java?rev=1344890&r1=1344889&r2=1344890&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/compiler/TestCompiler.java (original)
+++ tomcat/trunk/test/org/apache/jasper/compiler/TestCompiler.java Thu May 31 20:18:49 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/trunk/test/webapp-3.0/bug53257/index.jsp
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug53257/index.jsp?rev=1344890&r1=1344889&r2=1344890&view=diff
==============================================================================
--- tomcat/trunk/test/webapp-3.0/bug53257/index.jsp (original)
+++ tomcat/trunk/test/webapp-3.0/bug53257/index.jsp Thu May 31 20:18:49 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) {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org