Author: markt
Date: Wed Feb  9 23:41:32 2011
New Revision: 1069170

URL: http://svn.apache.org/viewvc?rev=1069170&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50721
Correctly handle URL decoding where the URL ends in %nn.
Patch (for fix) provided by Christof Marti.
Additional test cases added.

Modified:
    tomcat/trunk/java/org/apache/catalina/util/RequestUtil.java
    tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/util/RequestUtil.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/RequestUtil.java?rev=1069170&r1=1069169&r2=1069170&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/RequestUtil.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/RequestUtil.java Wed Feb  9 
23:41:32 2011
@@ -326,7 +326,7 @@ public final class RequestUtil {
             if (b == '+' && isQuery) {
                 b = (byte)' ';
             } else if (b == '%') {
-                if (ix + 2 >= len) {
+                if (ix + 2 > len) {
                     throw new IllegalArgumentException(
                             
sm.getString("requestUtil.urlDecode.missingDigit"));
                 }

Modified: tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java?rev=1069170&r1=1069169&r2=1069170&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java (original)
+++ tomcat/trunk/test/org/apache/catalina/util/TestRequestUtil.java Wed Feb  9 
23:41:32 2011
@@ -28,7 +28,7 @@ public class TestRequestUtil extends Tes
         assertEquals("/",RequestUtil.normalize("//"));
     }
 
-    public void testURLDecodeString() {
+    public void testURLDecodeStringInvalid() {
         // %n rather than %nn should throw an IAE according to the Javadoc
         Exception exception = null;
         try {
@@ -47,4 +47,40 @@ public class TestRequestUtil extends Tes
         }
         assertTrue(exception instanceof IllegalArgumentException);
     }
+    
+    public void testURLDecodeStringValidIso88591Start() {
+
+        String result = RequestUtil.URLDecode("%41xxxx", "ISO-8859-1");
+        assertEquals("Axxxx", result);
+    }
+
+    public void testURLDecodeStringValidIso88591Middle() {
+
+        String result = RequestUtil.URLDecode("xx%41xx", "ISO-8859-1");
+        assertEquals("xxAxx", result);
+    }
+
+    public void testURLDecodeStringValidIso88591End() {
+
+        String result = RequestUtil.URLDecode("xxxx%41", "ISO-8859-1");
+        assertEquals("xxxxA", result);
+    }
+
+    public void testURLDecodeStringValidUtf8Start() {
+        String result = RequestUtil.URLDecode("%c3%aaxxxx", "UTF-8");
+        assertEquals("\u00eaxxxx", result);
+    }
+
+    public void testURLDecodeStringValidUtf8Middle() {
+
+        String result = RequestUtil.URLDecode("xx%c3%aaxx", "UTF-8");
+        assertEquals("xx\u00eaxx", result);
+    }
+
+    public void testURLDecodeStringValidUtf8End() {
+
+        String result = RequestUtil.URLDecode("xxxx%c3%aa", "UTF-8");
+        assertEquals("xxxx\u00ea", result);
+    }
+
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1069170&r1=1069169&r2=1069170&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Feb  9 23:41:32 2011
@@ -64,8 +64,12 @@
         the expected state transitions. (markt)
       </add>
       <fix>
+        <bug>50721</bug>: Correctly handle URL decoding where the URL ends in
+        %nn. Patch provided by Christof Marti. (markt)
+      </fix>
+      <fix>
         <bug>50748</bug>: Allow the content length header to be set up to the
-        point the response is committed when a writer is beng used. (markt)
+        point the response is committed when a writer is being used. (markt)
       </fix>
     </changelog>
   </subsection>



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

Reply via email to