This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit a894442baf2c66807212d31c291af02edb2d04ad 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 0d59924..3ea84a7 100644 --- a/java/org/apache/catalina/connector/Response.java +++ b/java/org/apache/catalina/connector/Response.java @@ -769,9 +769,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 3af1861..7080a52 100644 --- a/java/org/apache/coyote/Response.java +++ b/java/org/apache/coyote/Response.java @@ -531,7 +531,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 15ecc3a..1111616 100644 --- a/test/org/apache/coyote/TestResponse.java +++ b/test/org/apache/coyote/TestResponse.java @@ -27,7 +27,6 @@ import javax.servlet.http.HttpServletRequest; import javax.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-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org