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,
+     * <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());
+
     }
 
 

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 @@
       <update>
         The poller now has good performance, so remove firstReadTimeout. (remm)
       </update>
+      <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="Webapps">



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to