harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r448785 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/org/apache/harmony/luni/util/Base64.java test/java/org/apache/harmony/luni/tests/util/ test/java/org/apache/harmony/luni/tests/util/Base64Test.java
Date Fri, 22 Sep 2006 03:16:27 GMT
Author: smishura
Date: Thu Sep 21 20:16:27 2006
New Revision: 448785

URL: http://svn.apache.org/viewvc?view=rev&rev=448785
Log:
Apply modified patch for HARMONY-1513 ([classlib][luni] Base64 fails on empty input.)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/util/
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/util/Base64Test.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Base64.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Base64.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Base64.java?view=diff&rev=448785&r1=448784&r2=448785
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Base64.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Base64.java
Thu Sep 21 20:16:27 2006
@@ -36,6 +36,10 @@
     public static byte[] decode(byte[] in, int len) {
         // approximate output length
         int length = len / 4 * 3;
+        // return an empty array on emtpy or short input without padding
+        if (length == 0) {
+            return new byte[0];
+        }
         // temporary array
         byte[] out = new byte[length];
         // number of padding characters ('=')

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/util/Base64Test.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/util/Base64Test.java?view=auto&rev=448785
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/util/Base64Test.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/util/Base64Test.java
Thu Sep 21 20:16:27 2006
@@ -0,0 +1,48 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.harmony.luni.tests.util;
+
+import org.apache.harmony.luni.util.Base64;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Base64 encoder/decoder test.
+ */
+public class Base64Test extends TestCase {
+
+    /**
+     * Checks the result on empty parameter.
+     */
+    public static void testDecodeEmpty() throws Exception {
+        // Regression for HARMONY-1513
+        byte[] result = Base64.decode(new byte[0]);
+        assertEquals("The length of the result differs from expected",
+                0, result.length);
+    }
+
+    public static Test suite() {
+        return new TestSuite(Base64Test.class);
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(suite());
+    }
+}
+



Mime
View raw message