tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1785032 - in /tomcat/trunk: java/org/apache/jasper/compiler/ test/org/apache/jasper/compiler/ test/webapp/WEB-INF/ test/webapp/jsp/encoding/ webapps/docs/
Date Wed, 01 Mar 2017 20:44:22 GMT
Author: markt
Date: Wed Mar  1 20:44:22 2017
New Revision: 1785032

URL: http://svn.apache.org/viewvc?rev=1785032&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=60769
Fix regression in JSP encoding detection refactoring

Added:
    tomcat/trunk/test/webapp/jsp/encoding/bug60769a.jspx
    tomcat/trunk/test/webapp/jsp/encoding/bug60769b.jspx
Modified:
    tomcat/trunk/java/org/apache/jasper/compiler/EncodingDetector.java
    tomcat/trunk/java/org/apache/jasper/compiler/ParserController.java
    tomcat/trunk/test/org/apache/jasper/compiler/TestEncodingDetector.java
    tomcat/trunk/test/webapp/WEB-INF/web.xml
    tomcat/trunk/test/webapp/jsp/encoding/README.txt
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/jasper/compiler/EncodingDetector.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/EncodingDetector.java?rev=1785032&r1=1785031&r2=1785032&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/EncodingDetector.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/EncodingDetector.java Wed Mar  1 20:44:22
2017
@@ -27,6 +27,9 @@ import javax.xml.stream.XMLStreamReader;
 /*
  * The BoM detection is derived from:
  * http://svn.us.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/xmlparser/XMLEncodingDetector.java?annotate=1742248
+ *
+ * The prolog is always at least as specific as the BOM therefore any encoding
+ * specified in the prolog should take priority over the BOM.
  */
 class EncodingDetector {
 
@@ -35,7 +38,8 @@ class EncodingDetector {
         XML_INPUT_FACTORY = XMLInputFactory.newFactory();
     }
 
-    private final BomResult bomResult;
+    private final String encoding;
+    private final int skip;
     private final boolean encodingSpecifiedInProlog;
 
 
@@ -50,7 +54,7 @@ class EncodingDetector {
         BufferedInputStream bis = new BufferedInputStream(is, 4);
         bis.mark(4);
 
-        bomResult = processBom(bis);
+        BomResult bomResult = processBom(bis);
 
         // Reset the stream back to the start to allow the XML prolog detection
         // to work. Skip any BoM we discovered.
@@ -59,17 +63,25 @@ class EncodingDetector {
             is.read();
         }
 
-        encodingSpecifiedInProlog = (getPrologEncoding(bis) != null);
+        String prologEncoding = getPrologEncoding(bis);
+        if (prologEncoding == null) {
+            encodingSpecifiedInProlog = false;
+            encoding = bomResult.encoding;
+        } else {
+            encodingSpecifiedInProlog = true;
+            encoding = prologEncoding;
+        }
+        skip = bomResult.skip;
     }
 
 
-    String getBomEncoding() {
-        return bomResult.encoding;
+    String getEncoding() {
+        return encoding;
     }
 
 
     int getSkip() {
-        return bomResult.skip;
+        return skip;
     }
 
 

Modified: tomcat/trunk/java/org/apache/jasper/compiler/ParserController.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/ParserController.java?rev=1785032&r1=1785031&r2=1785032&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/ParserController.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/ParserController.java Wed Mar  1 20:44:22
2017
@@ -321,7 +321,7 @@ class ParserController implements TagCon
             InputStream inStream = JspUtil.getInputStream(absFileName, jar, ctxt);
             EncodingDetector encodingDetector = new EncodingDetector(inStream);
 
-            sourceEnc = encodingDetector.getBomEncoding();
+            sourceEnc = encodingDetector.getEncoding();
             isEncodingSpecifiedInProlog = encodingDetector.isEncodingSpecifiedInProlog();
             isBomPresent = (encodingDetector.getSkip() > 0);
             skip = encodingDetector.getSkip();

Modified: tomcat/trunk/test/org/apache/jasper/compiler/TestEncodingDetector.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TestEncodingDetector.java?rev=1785032&r1=1785031&r2=1785032&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/compiler/TestEncodingDetector.java (original)
+++ tomcat/trunk/test/org/apache/jasper/compiler/TestEncodingDetector.java Wed Mar  1 20:44:22
2017
@@ -57,6 +57,8 @@ public class TestEncodingDetector extend
         result.add(new Object[] { "bom-utf16le-prolog-utf16be.jspx", Integer.valueOf(500),
null });
         result.add(new Object[] { "bom-utf16le-prolog-utf16le.jspx", Integer.valueOf(200),
Boolean.TRUE });
         result.add(new Object[] { "bom-utf16le-prolog-utf8.jspx",    Integer.valueOf(500),
null });
+        result.add(new Object[] { "bug60769a.jspx",    Integer.valueOf(500), null });
+        result.add(new Object[] { "bug60769b.jspx",    Integer.valueOf(200), Boolean.TRUE
});
         return result;
     }
 

Modified: tomcat/trunk/test/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/WEB-INF/web.xml?rev=1785032&r1=1785031&r2=1785032&view=diff
==============================================================================
--- tomcat/trunk/test/webapp/WEB-INF/web.xml (original)
+++ tomcat/trunk/test/webapp/WEB-INF/web.xml Wed Mar  1 20:44:22 2017
@@ -129,6 +129,16 @@
       <include-coda>/bug5nnnn/bug55262-coda.jspf</include-coda>
       <default-content-type>text/plain</default-content-type>
     </jsp-property-group>
+    <jsp-property-group>
+      <url-pattern>/jsp/encoding/bug60769a.jspx</url-pattern>
+      <page-encoding>UTF-8</page-encoding>
+      <is-xml>true</is-xml>
+    </jsp-property-group>
+    <jsp-property-group>
+      <url-pattern>/jsp/encoding/bug60769b.jspx</url-pattern>
+      <page-encoding>ISO-8859-1</page-encoding>
+      <is-xml>true</is-xml>
+    </jsp-property-group>
   </jsp-config>
 
   <servlet>

Modified: tomcat/trunk/test/webapp/jsp/encoding/README.txt
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/jsp/encoding/README.txt?rev=1785032&r1=1785031&r2=1785032&view=diff
==============================================================================
--- tomcat/trunk/test/webapp/jsp/encoding/README.txt (original)
+++ tomcat/trunk/test/webapp/jsp/encoding/README.txt Wed Mar  1 20:44:22 2017
@@ -17,7 +17,7 @@
 
 A number of the test files in this directory specify conflicting encoding
 in the BOM and and in the XML prolog. The rules for determining the actual
-encoding are as follows:
+encoding used in the file are as follows:
 
 1. If there is a BOM, use the encoding defined by the BOM.
 

Added: tomcat/trunk/test/webapp/jsp/encoding/bug60769a.jspx
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/jsp/encoding/bug60769a.jspx?rev=1785032&view=auto
==============================================================================
--- tomcat/trunk/test/webapp/jsp/encoding/bug60769a.jspx (added)
+++ tomcat/trunk/test/webapp/jsp/encoding/bug60769a.jspx Wed Mar  1 20:44:22 2017
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.3">
+  <jsp:directive.page contentType="text/plain" />
+  <jsp:text>OK</jsp:text>
+</jsp:root>
\ No newline at end of file

Added: tomcat/trunk/test/webapp/jsp/encoding/bug60769b.jspx
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/jsp/encoding/bug60769b.jspx?rev=1785032&view=auto
==============================================================================
--- tomcat/trunk/test/webapp/jsp/encoding/bug60769b.jspx (added)
+++ tomcat/trunk/test/webapp/jsp/encoding/bug60769b.jspx Wed Mar  1 20:44:22 2017
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.3">
+  <jsp:directive.page contentType="text/plain" />
+  <jsp:text>OK</jsp:text>
+</jsp:root>
\ No newline at end of file

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1785032&r1=1785031&r2=1785032&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Mar  1 20:44:22 2017
@@ -204,6 +204,12 @@
         Improve the error handling for simple tags to ensure that the tag is
         released and destroyed once used. (remm, violetagg)
       </fix>
+      <fix>
+        <bug>60769</bug>: Correct a regression in the XML encoding detection
+        refactoring carried out for 9.0.0.M16 that incorrectly always used the
+        detected BOM encoding in preference to any encoding specified in the
+        prolog. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Cluster">



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


Mime
View raw message