Author: markt
Date: Sun Jul 30 18:18:36 2017
New Revision: 1803444

URL: http://svn.apache.org/viewvc?rev=1803444&view=rev
Log:
Fix another BZ 49464 regression.

Modified:
    tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
    tomcat/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java?rev=1803444&r1=1803443&r2=1803444&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java Sun Jul 
30 18:18:36 2017
@@ -974,7 +974,18 @@ public class DefaultServlet extends Http
         String outputEncoding = response.getCharacterEncoding();
         Charset charset = B2CConverter.getCharset(outputEncoding);
         boolean conversionRequired;
+        /*
+         * The test below deliberately uses != to compare two Strings. This is
+         * because the code is looking to see if the default character encoding
+         * has been returned because no explicit character encoding has been
+         * defined. There is no clean way of doing this via the Servlet API. It
+         * would be possible to add a Tomcat specific API but that would 
require
+         * quite a bit of code to get to the Tomcat specific request object 
that
+         * may have been wrapped. The != test is a (slightly hacky) quick way 
of
+         * doing this.
+         */
         if (!usingPrecompressedVersion && isText(contentType) &&
+                outputEncoding != 
org.apache.coyote.Constants.DEFAULT_BODY_CHARSET.name() &&
                 !charset.equals(fileEncodingCharset)) {
             conversionRequired = true;
             // Conversion often results fewer/more/different bytes.

Modified: tomcat/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java?rev=1803444&r1=1803443&r2=1803444&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java Sun 
Jul 30 18:18:36 2017
@@ -787,19 +787,12 @@ public class TestDefaultServlet extends
         int rc = getUrl("http://localhost:"; + getPort() + 
"/bug49nnn/bug49464-ibm850.txt",
                 res, headers);
 
+        // This test relies on no content-type being specified in the response
+        // and the user agent correctly figuring out the content type
         Assert.assertEquals(HttpServletResponse.SC_OK, rc);
         List<String> values = headers.get("Content-Type");
-        if (values != null && values.size() == 1) {
-            MediaType mediaType = MediaType.parseMediaType(new 
StringReader(values.get(0)));
-            String charset = mediaType.getCharset();
-            if (charset == null) {
-                res.setCharset(StandardCharsets.ISO_8859_1);
-            } else {
-                res.setCharset(B2CConverter.getCharset(charset));
-            }
-        } else {
-            res.setCharset(StandardCharsets.ISO_8859_1);
-        }
+        Assert.assertNull(values);
+        res.setCharset(B2CConverter.getCharset("IBM850"));
         Assert.assertEquals("\u00bd", res.toString());
     }
 

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1803444&r1=1803443&r2=1803444&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Sun Jul 30 18:18:36 2017
@@ -48,6 +48,12 @@
   <subsection name="Catalina">
     <changelog>
       <fix>
+        Correct another regression in the fix for <bug>49464</bug> that could
+        corrupt static content when no character encoding was explicitly 
defined
+        for the response and the <code>DefaultServlet</code> used a
+        <code>fileEncoding</code> that was not ISO-8859-1.(markt)
+      </fix>
+      <fix>
         Correct a bug in the <code>PushBuilder</code> implementation that
         meant push URLs containing <code>%nn</code> sequences were not 
correctly
         decoded. Identified by FindBugs. (markt)



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

Reply via email to