From: fhanik Date: Mon, 6 Aug 2007 23:49:46 +0000 (+0000) Subject: forward port from markt bug fixes in 6.0.x branch X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0727a1f14d382e13d34412c6325c72d565529fe6;p=tomcat7.0 forward port from markt bug fixes in 6.0.x branch git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@563344 13f79535-47bb-0310-9956-ffa450edef68 --- 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/java/org/apache/jasper/servlet/JspServlet.java b/java/org/apache/jasper/servlet/JspServlet.java index 028e3e94a..c345d8ea1 100644 --- a/java/org/apache/jasper/servlet/JspServlet.java +++ b/java/org/apache/jasper/servlet/JspServlet.java @@ -305,8 +305,25 @@ public class JspServlet extends HttpServlet implements PeriodicEventListener { // Check if the requested JSP page exists, to avoid // creating unnecessary directories and files. if (null == context.getResource(jspUri)) { - response.sendError(HttpServletResponse.SC_NOT_FOUND, - request.getRequestURI()); + String includeRequestUri = (String) + request.getAttribute( + "javax.servlet.include.request_uri"); + if (includeRequestUri != null) { + // This file was included. Throw an exception as + // a response.sendError() will be ignored + throw new ServletException(Localizer.getMessage( + "jsp.error.file.not.found",jspUri)); + } else { + try { + response.sendError( + HttpServletResponse.SC_NOT_FOUND, + request.getRequestURI()); + } catch (IllegalStateException ise) { + log.error(Localizer.getMessage( + "jsp.error.file.not.found", + jspUri)); + } + } return; } boolean isErrorPage = exception != null; diff --git a/java/org/apache/jasper/servlet/JspServletWrapper.java b/java/org/apache/jasper/servlet/JspServletWrapper.java index 12d0cdcde..7df6a8871 100644 --- a/java/org/apache/jasper/servlet/JspServletWrapper.java +++ b/java/org/apache/jasper/servlet/JspServletWrapper.java @@ -328,25 +328,6 @@ public class JspServletWrapper { return; } - } catch (FileNotFoundException ex) { - ctxt.incrementRemoved(); - String includeRequestUri = (String) - request.getAttribute("javax.servlet.include.request_uri"); - if (includeRequestUri != null) { - // This file was included. Throw an exception as - // a response.sendError() will be ignored by the - // servlet engine. - throw new ServletException(ex); - } else { - try { - response.sendError(HttpServletResponse.SC_NOT_FOUND, - ex.getMessage()); - } catch (IllegalStateException ise) { - log.error(Localizer.getMessage("jsp.error.file.not.found", - ex.getMessage()), - ex); - } - } } catch (ServletException ex) { if (options.getDevelopment()) { throw handleJspException(ex);