Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 5811 invoked from network); 15 Apr 2007 00:23:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Apr 2007 00:23:17 -0000 Received: (qmail 70090 invoked by uid 500); 15 Apr 2007 00:23:15 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 70036 invoked by uid 500); 15 Apr 2007 00:23:15 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 70025 invoked by uid 500); 15 Apr 2007 00:23:15 -0000 Delivered-To: apmail-jakarta-tomcat-dev@jakarta.apache.org Received: (qmail 70022 invoked by uid 99); 15 Apr 2007 00:23:15 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 Apr 2007 17:23:15 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 Apr 2007 17:23:08 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 997441A9838; Sat, 14 Apr 2007 17:22:48 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r528896 - in /tomcat/tc6.0.x/trunk: java/org/apache/tomcat/util/http/ContentType.java webapps/docs/changelog.xml Date: Sun, 15 Apr 2007 00:22:48 -0000 To: tomcat-dev@jakarta.apache.org From: markt@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070415002248.997441A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: markt Date: Sat Apr 14 17:22:47 2007 New Revision: 528896 URL: http://svn.apache.org/viewvc?view=rev&rev=528896 Log: Fix bug 42119 using approach suggested by Leigh L Klotz Jr of using RequestUtil implementation. Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ContentType.java tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ContentType.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ContentType.java?view=diff&rev=528896&r1=528895&r2=528896 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ContentType.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ContentType.java Sat Apr 14 17:22:47 2007 @@ -29,27 +29,30 @@ */ 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, + * null 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()); + } Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?view=diff&rev=528896&r1=528895&r2=528896 ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Sat Apr 14 17:22:47 2007 @@ -153,6 +153,11 @@ The poller now has good performance, so remove firstReadTimeout. (remm) + + 42119 Fix return value for request.getCharacterEncoding() when + Content-Type headers contain parameters other than charset. Patch by + Leigh L Klotz Jr. (markt) + --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org