Author: violetagg
Date: Thu Mar 14 13:56:32 2013
New Revision: 1456440

URL: http://svn.apache.org/r1456440
Log:
Fix the recycling of the o.a.t.u.buf.UEncoder.output field. 
Fix javadoc. 
Add a test case.

Added:
    tomcat/trunk/test/org/apache/tomcat/util/buf/TestUEncoder.java   (with 
props)
Modified:
    tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java?rev=1456440&r1=1456439&r2=1456440&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java Thu Mar 14 
13:56:32 2013
@@ -51,9 +51,12 @@ public final class UEncoder {
     }
 
 
-    /** URL Encode string, using a specified encoding.
+   /**
+    * URL Encode string, using a specified encoding.
     *
     * @param s string to be encoded
+    * @param start the beginning index, inclusive
+    * @param end the ending index, exclusive
     * @throws IOException If an I/O error occurs
     */
    public CharChunk encodeURL(String s, int start, int end)
@@ -66,6 +69,7 @@ public final class UEncoder {
        } else {
            bb.recycle();
            cb.recycle();
+           output.recycle();
        }
 
        for (int i = start; i < end; i++) {

Added: tomcat/trunk/test/org/apache/tomcat/util/buf/TestUEncoder.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/buf/TestUEncoder.java?rev=1456440&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/buf/TestUEncoder.java (added)
+++ tomcat/trunk/test/org/apache/tomcat/util/buf/TestUEncoder.java Thu Mar 14 
13:56:32 2013
@@ -0,0 +1,49 @@
+/*
+ *  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.
+ */
+
+package org.apache.tomcat.util.buf;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+/**
+ * Test cases for {@link UEncoder}.
+ */
+public class TestUEncoder {
+
+    @Test
+    public void testEncodeURL() throws IOException {
+        UEncoder urlEncoder = new UEncoder();
+
+        String s = "a/b/c/d+e.class";
+        assertTrue(urlEncoder.encodeURL(s, 0, s.length()).equals(
+                "a%2fb%2fc%2fd%2be.class"));
+        assertTrue(urlEncoder.encodeURL(s, 2, s.length() - 2).equals(
+                "b%2fc%2fd%2be.cla"));
+
+        urlEncoder.addSafeCharacter('+');
+        assertTrue(urlEncoder.encodeURL(s, 0, s.length()).equals(
+                "a%2fb%2fc%2fd+e.class"));
+
+        s = new String(new char[] { 0xD801, 0xDC01 });
+        assertTrue(urlEncoder.encodeURL(s, 0, s.length())
+                .equals("%f0%90%90%81"));
+    }
+}

Propchange: tomcat/trunk/test/org/apache/tomcat/util/buf/TestUEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to