This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new a2ec03a342 Simplify and enhance charset extraction from content type
(#662)
a2ec03a342 is described below
commit a2ec03a34276792b42f66182c407f2f8c791dcc1
Author: wyc <[email protected]>
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 3bbd9fd8a6..9c36b4dc18 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;
@@ -35,6 +36,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;
@@ -857,20 +859,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: [email protected]
For additional commands, e-mail: [email protected]