Author: markt
Date: Mon Mar  4 13:28:02 2013
New Revision: 1452295

URL: http://svn.apache.org/r1452295
Log:
Switch B2CConverter to use Tomcat's Harmony based UTF-8 decoder

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java
    tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteAdapter.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java?rev=1452295&r1=1452294&r2=1452295&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java Mon Mar  4 
13:28:02 2013
@@ -117,7 +117,15 @@ public class B2CConverter {
         } else {
             action = CodingErrorAction.REPORT;
         }
-        decoder = getCharset(encoding).newDecoder();
+        Charset charset = getCharset(encoding);
+        // Special case. Use the Apache Harmony based UTF-8 decoder because it
+        // - a) rejects invalid sequences that the JVM decoder does not
+        // - b) fails faster for some invalid sequences
+        if (charset.equals(UTF_8)) {
+            decoder = new Utf8Decoder();
+        } else {
+            decoder = charset.newDecoder();
+        }
         decoder.onMalformedInput(action);
         decoder.onUnmappableCharacter(action);
     }

Modified: tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteAdapter.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteAdapter.java?rev=1452295&r1=1452294&r2=1452295&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteAdapter.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestCoyoteAdapter.java Mon 
Mar  4 13:28:02 2013
@@ -204,10 +204,7 @@ public class TestCoyoteAdapter extends T
     @Test
     public void testBug54602e() throws Exception {
         // Invalid UTF-8
-        doTestUriDecoding("/foo%ed%a0%80", "UTF-8", "/foo\uD800");
-        // TODO Requires a switch to the Harmony based decoder to fix this
-        // Should be
-        //doTestUriDecoding("/foo%ed%a0%80", "UTF-8", "/foo\uFFFD");
+        doTestUriDecoding("/foo%ed%a0%80", "UTF-8", "/foo\uFFFD\uFFFD\uFFFD");
     }
 
     private void doTestUriDecoding(String path, String encoding,



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

Reply via email to