This is an automated email from the ASF dual-hosted git repository. coheigea pushed a commit to branch 3.2.x-fixes in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.2.x-fixes by this push: new d82cc1e CXF-7858 - Base64 empty string encoding issue d82cc1e is described below commit d82cc1e12231f4fc07596dba82b80947b8ae796e Author: Colm O hEigeartaigh <cohei...@apache.org> AuthorDate: Mon Oct 1 18:34:17 2018 +0100 CXF-7858 - Base64 empty string encoding issue (cherry picked from commit 802a80c77641c423be6dfc0b9f85cfc553067c26) --- .../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())); + } }