[ 
https://issues.apache.org/jira/browse/CXF-7858?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16635206#comment-16635206
 ] 

ASF GitHub Bot commented on CXF-7858:
-------------------------------------

coheigea closed pull request #452: CXF-7858 fix decoding too
URL: https://github.com/apache/cxf/pull/452
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/java/org/apache/cxf/common/util/Base64Utility.java 
b/core/src/main/java/org/apache/cxf/common/util/Base64Utility.java
index a3ae330c6b2..459c3749023 100644
--- a/core/src/main/java/org/apache/cxf/common/util/Base64Utility.java
+++ b/core/src/main/java/org/apache/cxf/common/util/Base64Utility.java
@@ -130,6 +130,10 @@ private Base64Utility() {
                                      int l)
         throws Base64Exception {
 
+        if (id != null && id.length == 0 && l == 0) {
+            return new byte[]{};
+        }
+
         // Keep it simple - must be >= 4. Unpadded
         // base64 data contain < 3 octets is invalid.
         //
diff --git 
a/core/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java 
b/core/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java
index ff61b802a75..6062822a5de 100644
--- a/core/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java
+++ b/core/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java
@@ -179,6 +179,9 @@ public void testVectors() throws Exception {
         assertEquals("Zm9vYg==", Base64Utility.encode("foob".getBytes()));
         assertEquals("Zm9vYmE=", Base64Utility.encode("fooba".getBytes()));
         assertEquals("Zm9vYmFy", Base64Utility.encode("foobar".getBytes()));
+
+        //decode
+        assertArrayEquals(new byte[]{}, Base64Utility.decode(""));
     }
 
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Base64 empty string encoding issue
> ----------------------------------
>
>                 Key: CXF-7858
>                 URL: https://issues.apache.org/jira/browse/CXF-7858
>             Project: CXF
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 3.2.6
>            Reporter: Andriy Mahats
>            Assignee: Colm O hEigeartaigh
>            Priority: Blocker
>             Fix For: 3.2.7, 3.1.18
>
>
> {code:java}
> char[] chunk = Base64Utility.encodeChunk("".getBytes(), 0, 0, true); // chunk 
>  = null after evaluation
> {code}
> According to [https://tools.ietf.org/html/rfc4648#section-10]
> h2. [10|https://tools.ietf.org/html/rfc4648#section-10]. Test Vectors
>  
>  BASE64("") = ""
>  
> {code:java}
> // later it evaluates to null
> //org.apache.cxf.common.util.Base64UrlUtility#encodeChunk
>  public static String encodeChunk(byte[] id, int offset, int length) {
>         char[] chunk = Base64Utility.encodeChunk(id, offset, length, true);
>         return chunk != null ? new String(chunk) : null;
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to