You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2018/10/01 17:35:03 UTC
[cxf] branch master updated: CXF-7858 - Base64 empty string
encoding issue
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new 802a80c CXF-7858 - Base64 empty string encoding issue
802a80c is described below
commit 802a80c77641c423be6dfc0b9f85cfc553067c26
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Oct 1 18:34:17 2018 +0100
CXF-7858 - Base64 empty string encoding issue
---
.../main/java/org/apache/cxf/common/util/Base64Utility.java | 4 +++-
.../java/org/apache/cxf/common/util/Base64UtilityTest.java | 11 +++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
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 77c9410..a3ae330 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
@@ -263,7 +263,9 @@ public final class Base64Utility {
int o,
int l,
boolean urlSafe) {
- if (l <= 0) {
+ if (id != null && id.length == 0 && l == 0) {
+ return new char[0];
+ } else if (l <= 0) {
return null;
}
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 93adf53..ff61b80 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
@@ -169,5 +169,16 @@ public class Base64UtilityTest extends Assert {
}
+ // See https://tools.ietf.org/html/rfc4648#section-10
+ @Test
+ public void testVectors() throws Exception {
+ assertEquals("", Base64Utility.encode("".getBytes()));
+ assertEquals("Zg==", Base64Utility.encode("f".getBytes()));
+ assertEquals("Zm8=", Base64Utility.encode("fo".getBytes()));
+ assertEquals("Zm9v", Base64Utility.encode("foo".getBytes()));
+ assertEquals("Zm9vYg==", Base64Utility.encode("foob".getBytes()));
+ assertEquals("Zm9vYmE=", Base64Utility.encode("fooba".getBytes()));
+ assertEquals("Zm9vYmFy", Base64Utility.encode("foobar".getBytes()));
+ }
}