This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-codec.git
commit 4bae73783fc2da7ff66e4c74090f353531527807 Author: Gary Gregory <[email protected]> AuthorDate: Wed Jan 14 18:58:04 2026 -0500 Sort members --- .../apache/commons/codec/binary/Base64Test.java | 120 ++++++++++----------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/src/test/java/org/apache/commons/codec/binary/Base64Test.java b/src/test/java/org/apache/commons/codec/binary/Base64Test.java index 41c008e9..d297b848 100644 --- a/src/test/java/org/apache/commons/codec/binary/Base64Test.java +++ b/src/test/java/org/apache/commons/codec/binary/Base64Test.java @@ -519,12 +519,72 @@ class Base64Test { assertThrows(IllegalArgumentException.class, () -> Base64.builder().setEncodeTable(encodeTable).get()); } + @Test + void testDecodeBase64DiffChars() { + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64("Zm9vYmF")); + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97, 126 }, Base64.decodeBase64("Zm9vYmF+")); + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97, 126 }, Base64.decodeBase64("Zm9vYmF-")); + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64("Zm9vYmF~")); + } + + @Test + void testDecodeBase64StandardDiffChars() { + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64Standard("Zm9vYmF")); + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97, 126 }, Base64.decodeBase64Standard("Zm9vYmF+")); + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64Standard("Zm9vYmF-")); + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64("Zm9vYmF~")); + } + + @Test + void testDecodeBase64UrlDiffChars() { + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64UrlSafe("Zm9vYmF")); + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64UrlSafe("Zm9vYmF+")); + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97, 126 }, Base64.decodeBase64UrlSafe("Zm9vYmF-")); + assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64("Zm9vYmF~")); + } + private void testDecodeEncode(final String encodedText) { final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64(encodedText)); final String encodedText2 = Base64.encodeBase64String(StringUtils.getBytesUtf8(decodedText)); assertEquals(encodedText, encodedText2); } + @ParameterizedTest + @ValueSource(strings = { + "", + "Zg==", + "Zm8=", + "Zm9v", + "Zm9vYg==", + "Zm9vYmE=", + "Zm9vYmFy", + "Zm9vYmF+", + "Zm9vYmF/" + }) + void testDecodeEncodeStandard(final String encodedText) { + final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64Standard(encodedText)); + final String encodedText2 = Base64.encodeBase64String(StringUtils.getBytesUtf8(decodedText)); + assertEquals(encodedText, encodedText2); + } + + @ParameterizedTest + @ValueSource(strings = { + "", + "Zg", + "Zm8", + "Zm9v", + "Zm9vYg", + "Zm9vYmE", + "Zm9vYmFy", + "Zm9vYmF-", + "Zm9vYmF_" + }) + void testDecodeEncodeUrl(final String encodedText) { + final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64UrlSafe(encodedText)); + final String encodedText2 = Base64.encodeBase64URLSafeString(StringUtils.getBytesUtf8(decodedText)); + assertEquals(encodedText, encodedText2); + } + /** * Tests conditional true branch for "marker0" test. */ @@ -952,66 +1012,6 @@ class Base64Test { testDecodeEncode(input); } - @ParameterizedTest - @ValueSource(strings = { - "", - "Zg==", - "Zm8=", - "Zm9v", - "Zm9vYg==", - "Zm9vYmE=", - "Zm9vYmFy", - "Zm9vYmF+", - "Zm9vYmF/" - }) - void testDecodeEncodeStandard(final String encodedText) { - final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64Standard(encodedText)); - final String encodedText2 = Base64.encodeBase64String(StringUtils.getBytesUtf8(decodedText)); - assertEquals(encodedText, encodedText2); - } - - @ParameterizedTest - @ValueSource(strings = { - "", - "Zg", - "Zm8", - "Zm9v", - "Zm9vYg", - "Zm9vYmE", - "Zm9vYmFy", - "Zm9vYmF-", - "Zm9vYmF_" - }) - void testDecodeEncodeUrl(final String encodedText) { - final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64UrlSafe(encodedText)); - final String encodedText2 = Base64.encodeBase64URLSafeString(StringUtils.getBytesUtf8(decodedText)); - assertEquals(encodedText, encodedText2); - } - - @Test - void testDecodeBase64DiffChars() { - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64("Zm9vYmF")); - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97, 126 }, Base64.decodeBase64("Zm9vYmF+")); - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97, 126 }, Base64.decodeBase64("Zm9vYmF-")); - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64("Zm9vYmF~")); - } - - @Test - void testDecodeBase64StandardDiffChars() { - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64Standard("Zm9vYmF")); - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97, 126 }, Base64.decodeBase64Standard("Zm9vYmF+")); - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64Standard("Zm9vYmF-")); - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64("Zm9vYmF~")); - } - - @Test - void testDecodeBase64UrlDiffChars() { - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64UrlSafe("Zm9vYmF")); - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64UrlSafe("Zm9vYmF+")); - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97, 126 }, Base64.decodeBase64UrlSafe("Zm9vYmF-")); - assertArrayEquals(new byte[] { 102, 111, 111, 98, 97 }, Base64.decodeBase64("Zm9vYmF~")); - } - /** * Tests RFC 4648 section 10 test vectors. * <ul>
