This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 6691ad1b22 Simplify and enhance charset extraction from content type (#662) 6691ad1b22 is described below commit 6691ad1b22ee8fe190a8c2ca7594d689950341a4 Author: wyc <rltgjqmduftl...@gmail.com> AuthorDate: Thu Sep 7 05:24:04 2023 +0900 Simplify and enhance charset extraction from content type (#662) Using MediaType to comply with specifications --- java/org/apache/coyote/Request.java | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/java/org/apache/coyote/Request.java b/java/org/apache/coyote/Request.java index 0520140ef6..903b5e2804 100644 --- a/java/org/apache/coyote/Request.java +++ b/java/org/apache/coyote/Request.java @@ -17,6 +17,7 @@ package org.apache.coyote; import java.io.IOException; +import java.io.StringReader; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.HashMap; @@ -31,6 +32,7 @@ import org.apache.tomcat.util.buf.UDecoder; import org.apache.tomcat.util.http.MimeHeaders; import org.apache.tomcat.util.http.Parameters; import org.apache.tomcat.util.http.ServerCookies; +import org.apache.tomcat.util.http.parser.MediaType; import org.apache.tomcat.util.net.ApplicationBufferHandler; import org.apache.tomcat.util.res.StringManager; @@ -790,20 +792,17 @@ public final class Request { 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); + + MediaType mediaType = null; + try { + mediaType = MediaType.parseMediaType(new StringReader(contentType)); + } catch (IOException e) { + // Ignore - null test below handles this } - encoding = encoding.trim(); - if (encoding.length() > 2 && encoding.startsWith("\"") && encoding.endsWith("\"")) { - encoding = encoding.substring(1, encoding.length() - 1); + if (mediaType != null) { + return mediaType.getCharset(); } - return encoding.trim(); + return null; } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org