From e53358e90fe77d2a3d55fee1b0609d262710279a Mon Sep 17 00:00:00 2001 From: markt Date: Sat, 4 Aug 2007 16:17:22 +0000 Subject: [PATCH] Port fix for bug 42944. + should only decoded to space in query strings. 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 | 48 ++++++++++++++++++++------ webapps/docs/changelog.xml | 4 +++ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/java/org/apache/catalina/util/RequestUtil.java b/java/org/apache/catalina/util/RequestUtil.java index c85924302..bce1df241 100644 --- a/java/org/apache/catalina/util/RequestUtil.java +++ b/java/org/apache/catalina/util/RequestUtil.java @@ -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) diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 26ba9613f..3e8601e49 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -19,6 +19,10 @@ + 42944: Correctly handle servlet mappings that use a '+' + character as part of the url pattern. (markt) + + 42951: 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 -- 2.11.0