Port fix for bug 42944. + should only decoded to space in query strings.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 4 Aug 2007 16:17:22 +0000 (16:17 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 4 Aug 2007 16:17:22 +0000 (16:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@562736 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/util/RequestUtil.java
webapps/docs/changelog.xml

index c859243..bce1df2 100644 (file)
@@ -187,7 +187,7 @@ public final class RequestUtil {
      * Decode and return the specified URL-encoded String.
      * When the byte array is converted to a string, the system default
      * character encoding is used...  This may be different than some other
-     * servers.
+     * servers. It is assumed the string is not a query string.
      *
      * @param str The url-encoded string
      *
@@ -195,14 +195,13 @@ public final class RequestUtil {
      * by a valid 2-digit hexadecimal number
      */
     public static String URLDecode(String str) {
-
         return URLDecode(str, null);
-
     }
-
-
+    
+    
     /**
-     * Decode and return the specified URL-encoded String.
+     * Decode and return the specified URL-encoded String. It is assumed the
+     * string is not a query string.
      *
      * @param str The url-encoded string
      * @param enc The encoding to use; if null, the default encoding is used
@@ -210,7 +209,19 @@ public final class RequestUtil {
      * by a valid 2-digit hexadecimal number
      */
     public static String URLDecode(String str, String enc) {
-
+        return URLDecode(str, enc, false);
+    }
+    
+    /**
+     * Decode and return the specified URL-encoded String.
+     *
+     * @param str The url-encoded string
+     * @param enc The encoding to use; if null, the default encoding is used
+     * @param isQuery Is this a query string being processed
+     * @exception IllegalArgumentException if a '%' character is not followed
+     * by a valid 2-digit hexadecimal number
+     */
+    public static String URLDecode(String str, String enc, boolean isQuery) {
         if (str == null)
             return (null);
 
@@ -226,13 +237,14 @@ public final class RequestUtil {
             }
         } catch (UnsupportedEncodingException uee) {}
 
-        return URLDecode(bytes, enc);
+        return URLDecode(bytes, enc, isQuery);
 
     }
 
 
     /**
-     * Decode and return the specified URL-encoded byte array.
+     * Decode and return the specified URL-encoded byte array. It is assumed
+     * the string is not a query string.
      *
      * @param bytes The url-encoded byte array
      * @exception IllegalArgumentException if a '%' character is not followed
@@ -244,7 +256,8 @@ public final class RequestUtil {
 
 
     /**
-     * Decode and return the specified URL-encoded byte array.
+     * Decode and return the specified URL-encoded byte array. It is assumed
+     * the string is not a query string.
      *
      * @param bytes The url-encoded byte array
      * @param enc The encoding to use; if null, the default encoding is used
@@ -252,7 +265,20 @@ public final class RequestUtil {
      * by a valid 2-digit hexadecimal number
      */
     public static String URLDecode(byte[] bytes, String enc) {
+        return URLDecode(bytes, null, false);
+    }
 
+    /**
+     * Decode and return the specified URL-encoded byte array.
+     *
+     * @param bytes The url-encoded byte array
+     * @param enc The encoding to use; if null, the default encoding is used
+     * @param isQuery Is this a query string being processed
+     * @exception IllegalArgumentException if a '%' character is not followed
+     * by a valid 2-digit hexadecimal number
+     */
+    public static String URLDecode(byte[] bytes, String enc, boolean isQuery) {
+    
         if (bytes == null)
             return (null);
 
@@ -261,7 +287,7 @@ public final class RequestUtil {
         int ox = 0;
         while (ix < len) {
             byte b = bytes[ix++];     // Get byte to test
-            if (b == '+') {
+            if (b == '+' && isQuery) {
                 b = (byte)' ';
             } else if (b == '%') {
                 b = (byte) ((convertHexDigit(bytes[ix++]) << 4)
index 26ba961..3e8601e 100644 (file)
   <subsection name="Catalina">
     <changelog>
       <fix>
+        <bug>42944</bug>: Correctly handle servlet mappings that use a '+'
+        character as part of the url pattern. (markt)
+      </fix>
+      <fix>
          <bug>42951</bug>: Don't use CATALINA_OPTS when stopping Tomcat. This
          allows options for starting and stopping to be set on JAVA_OPTS and
          options for starting only to be set on CATALINA_OPTS. Without this