Author: markt Date: Sat Apr 14 17:25:52 2007 New Revision: 528898 URL: http://svn.apache.org/viewvc?view=rev&rev=528898 Log: Fix bug 42119 using approach suggested by Leigh L Klotz Jr of using RequestUtil implementation.
Modified: tomcat/connectors/trunk/util/java/org/apache/tomcat/util/http/ContentType.java tomcat/container/tc5.5.x/webapps/docs/changelog.xml Modified: tomcat/connectors/trunk/util/java/org/apache/tomcat/util/http/ContentType.java URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/util/java/org/apache/tomcat/util/http/ContentType.java?view=diff&rev=528898&r1=528897&r2=528898 ============================================================================== --- tomcat/connectors/trunk/util/java/org/apache/tomcat/util/http/ContentType.java (original) +++ tomcat/connectors/trunk/util/java/org/apache/tomcat/util/http/ContentType.java Sat Apr 14 17:25:52 2007 @@ -29,30 +29,32 @@ */ public class ContentType { - // Basically return everything after ";charset=" - // If no charset specified, use the HTTP default (ASCII) character set. - public static String getCharsetFromContentType(String type) { - if (type == null) { - return null; - } - int semi = type.indexOf(";"); - if (semi == -1) { - return null; - } - int charsetLocation = type.indexOf("charset=", semi); - if (charsetLocation == -1) { - return null; - } - String afterCharset = type.substring(charsetLocation + 8); - // The charset value in a Content-Type header is allowed to be quoted - // and charset values can't contain quotes. Just convert any quote - // chars into spaces and let trim clean things up. - afterCharset = afterCharset.replace('"', ' '); - String encoding = afterCharset.trim(); - return encoding; - } + /** + * Parse the character encoding from the specified content type header. + * If the content type is null, or there is no explicit character encoding, + * <code>null</code> is returned. + * + * @param contentType a content type header + */ + public static String getCharsetFromContentType(String contentType) { + if (contentType == null) + return (null); + int start = contentType.indexOf("charset="); + if (start < 0) + return (null); + String encoding = contentType.substring(start + 8); + int end = encoding.indexOf(';'); + if (end >= 0) + encoding = encoding.substring(0, end); + encoding = encoding.trim(); + if ((encoding.length() > 2) && (encoding.startsWith("\"")) + && (encoding.endsWith("\""))) + encoding = encoding.substring(1, encoding.length() - 1); + return (encoding.trim()); + } + /** * Returns true if the given content type contains a charset component, * false otherwise. Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/changelog.xml?view=diff&rev=528898&r1=528897&r2=528898 ============================================================================== --- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original) +++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Sat Apr 14 17:25:52 2007 @@ -85,6 +85,11 @@ <bug>41675</bug> Add a couple of DEBUG-level logging statements to Http11Processors when sending error responses. Patch by Ralf Hauser. (yoavs) </add> + <fix> + <bug>42119</bug> Fix return value for request.getCharacterEncoding() when + Content-Type headers contain parameters other than charset. Patch by + Leigh L Klotz Jr. (markt) + </fix> </changelog> </subsection> <subsection name="Cluster"> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]