You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/04/03 18:24:13 UTC

[tomcat] 01/03: Don't mutate a valid Content-type if it does not contain a charset

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 53f678ed9a0f9ff81abb6650fb0e553278a2a319
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Apr 3 19:20:34 2020 +0100

    Don't mutate a valid Content-type if it does not contain a charset
---
 java/org/apache/catalina/connector/Response.java | 12 ++++++++++--
 java/org/apache/coyote/Response.java             |  9 ++++++++-
 test/org/apache/coyote/TestResponse.java         |  2 --
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/catalina/connector/Response.java b/java/org/apache/catalina/connector/Response.java
index 9e4b77e..af9c811 100644
--- a/java/org/apache/catalina/connector/Response.java
+++ b/java/org/apache/catalina/connector/Response.java
@@ -734,9 +734,17 @@ public class Response implements HttpServletResponse {
             return;
         }
 
-        getCoyoteResponse().setContentTypeNoCharset(m[0]);
 
-        if (m[1] != null) {
+        if (m[1] == null) {
+            // No charset and we know value is valid as cache lookup was
+            // successful
+            // Pass-through user provided value in case user-agent is buggy and
+            // requires specific format
+            getCoyoteResponse().setContentTypeNoCharset(type);
+        } else {
+            // There is a charset so have to rebuild content-type without it
+            getCoyoteResponse().setContentTypeNoCharset(m[0]);
+
             // Ignore charset if getWriter() has already been called
             if (!usingWriter) {
                 try {
diff --git a/java/org/apache/coyote/Response.java b/java/org/apache/coyote/Response.java
index 38cc609..91473a1 100644
--- a/java/org/apache/coyote/Response.java
+++ b/java/org/apache/coyote/Response.java
@@ -554,7 +554,14 @@ public final class Response {
 
         String charsetValue = m.getCharset();
 
-        if (charsetValue != null) {
+        if (charsetValue == null) {
+            // No charset and we know value is valid as parser was successful
+            // Pass-through user provided value in case user-agent is buggy and
+            // requires specific format
+            this.contentType = type;
+        } else {
+            // There is a charset so have to rebuild content-type without it
+            this.contentType = m.toStringNoCharset();
             charsetValue = charsetValue.trim();
             if (charsetValue.length() > 0) {
                 try {
diff --git a/test/org/apache/coyote/TestResponse.java b/test/org/apache/coyote/TestResponse.java
index 1ed01a7..f87e524 100644
--- a/test/org/apache/coyote/TestResponse.java
+++ b/test/org/apache/coyote/TestResponse.java
@@ -27,7 +27,6 @@ import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
 
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import org.apache.catalina.Context;
@@ -86,7 +85,6 @@ public class TestResponse extends TomcatBaseTest {
     }
 
 
-    @Ignore // Disabled until Bug 62912 is addressed
     @Test
     public void testContentTypeWithoutSpace() throws Exception {
         doTestContentTypeSpacing(false);


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org