Author: ggregory
Date: Sat Sep 23 16:41:53 2017
New Revision: 1809441
URL: http://svn.apache.org/viewvc?rev=1809441&view=rev
Log:
[CODEC-234] Base32.decode should support lowercase letters.
Modified:
commons/proper/codec/trunk/src/changes/changes.xml
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base32.java
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32Test.java
Modified: commons/proper/codec/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/changes/changes.xml?rev=1809441&r1=1809440&r2=1809441&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/changes/changes.xml (original)
+++ commons/proper/codec/trunk/src/changes/changes.xml Sat Sep 23 16:41:53 2017
@@ -45,6 +45,7 @@ The <action> type attribute can be add,u
<release version="1.11" date="2017-MM-DD" description="Feature and fix
release.">
<!-- The first attribute below should be the issue id; makes it easier
to navigate in the IDE outline -->
+ <action issue="CODEC-234" dev="ggregory" type="update"
due-to="Christopher Schultz, Sebb">Base32.decode should support lowercase
letters</action>
<action issue="CODEC-233" dev="sebb" type="update" due-to="Yossi
Tamari">Soundex should support more algorithm variants</action>
<action issue="CODEC-145" dev="sebb" type="fix" due-to="Jesse
Glick">Base64.encodeBase64String could better use newStringUsAscii (ditto
encodeBase64URLSafeString)</action>
<action issue="CODEC-144" dev="sebb" type="fix">BaseNCodec:
encodeToString and encodeAsString methods are identical</action>
Modified:
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base32.java
URL:
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base32.java?rev=1809441&r1=1809440&r2=1809441&view=diff
==============================================================================
---
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base32.java
(original)
+++
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base32.java
Sat Sep 23 16:41:53 2017
@@ -72,6 +72,9 @@ public class Base32 extends BaseNCodec {
-1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1, //
30-3f 2-7
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, //
40-4f A-O
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, //
50-5a P-Z
+ -1, -1, -1, -1, -1, //
5b - 5f
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, //
60 - 6f a-o
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, //
70 - 7a p-z/**/
};
/**
@@ -96,7 +99,10 @@ public class Base32 extends BaseNCodec {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
20-2f
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, //
30-3f 2-7
-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, //
40-4f A-O
- 25, 26, 27, 28, 29, 30, 31, //
50-57 P-V
+ 25, 26, 27, 28, 29, 30, 31, //
50-56 P-V
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, //
57-5f Z-_
+ -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, //
60-6f `-o
+ 25, 26, 27, 28, 29, 30, 31 //
70-76 p-v
};
/**
Modified:
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32Test.java
URL:
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32Test.java?rev=1809441&r1=1809440&r2=1809441&view=diff
==============================================================================
---
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32Test.java
(original)
+++
commons/proper/codec/trunk/src/test/java/org/apache/commons/codec/binary/Base32Test.java
Sat Sep 23 16:41:53 2017
@@ -19,6 +19,7 @@
package org.apache.commons.codec.binary;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -26,6 +27,7 @@ import java.nio.charset.Charset;
import java.util.Arrays;
import org.apache.commons.codec.Charsets;
+import org.apache.commons.codec.DecoderException;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;
@@ -44,6 +46,26 @@ public class Base32Test {
{"foobar" ,"MZXW6YTBOI======"},
};
+ private static final Object[][] BASE32_BINARY_TEST_CASES;
+
+ // { null, "O0o0O0o0" }
+// BASE32_BINARY_TEST_CASES[2][0] = new Hex().decode("739ce739ce");
+
+ static {
+ Hex hex = new Hex();
+ try {
+ BASE32_BINARY_TEST_CASES = new Object[][] {
+ new Object[] {
hex.decode("623a01735836e9a126e12fbf95e013ee6892997c"),
+ "MI5AC42YG3U2CJXBF67ZLYAT5ZUJFGL4" },
+ new Object[] {
hex.decode("623a01735836e9a126e12fbf95e013ee6892997c"),
+ "mi5ac42yg3u2cjxbf67zlyat5zujfgl4" },
+ new Object[] { hex.decode("739ce42108"),
+ "OOOOIIII" }
+ };
+ } catch (DecoderException de) {
+ throw new Error(":(", de);
+ }
+ }
private static final String [][] BASE32HEX_TEST_CASES = { // RFC 4648
{"" ,""},
{"f" ,"CO======"},
@@ -54,7 +76,6 @@ public class Base32Test {
{"foobar" ,"CPNMUOJ1E8======"},
};
-
private static final String [][] BASE32_TEST_CASES_CHUNKED = { //Chunked
{"" ,""},
{"f" ,"MY======\r\n"},
@@ -117,6 +138,22 @@ public class Base32Test {
}
@Test
+ public void testBase32HexSamplesReverse() throws Exception {
+ final Base32 codec = new Base32(true);
+ for (final String[] element : BASE32HEX_TEST_CASES) {
+ assertEquals(element[0], new String(codec.decode(element[1]),
CHARSET_UTF8));
+ }
+ }
+
+ @Test
+ public void testBase32HexSamplesReverseLowercase() throws Exception {
+ final Base32 codec = new Base32(true);
+ for (final String[] element : BASE32HEX_TEST_CASES) {
+ assertEquals(element[0], new
String(codec.decode(element[1].toLowerCase()), CHARSET_UTF8));
+ }
+ }
+
+ @Test
public void testBase32Samples() throws Exception {
final Base32 codec = new Base32();
for (final String[] element : BASE32_TEST_CASES) {
@@ -124,6 +161,27 @@ public class Base32Test {
}
}
+ @Test
+ public void testBase32BinarySamples() throws Exception {
+ final Base32 codec = new Base32();
+ for (final Object[] element : BASE32_BINARY_TEST_CASES) {
+ String expected;
+ if(element.length > 2)
+ expected = (String)element[2];
+ else
+ expected = (String)element[1];
+ assertEquals(expected.toUpperCase(),
codec.encodeAsString((byte[])element[0]));
+ }
+ }
+
+ @Test
+ public void testBase32BinarySamplesReverse() throws Exception {
+ final Base32 codec = new Base32();
+ for (final Object[] element : BASE32_BINARY_TEST_CASES) {
+ assertArrayEquals((byte[])element[0],
codec.decode((String)element[1]));
+ }
+ }
+
@Test
public void testBase32SamplesNonDefaultPadding() throws Exception {
final Base32 codec = new Base32((byte)0x25); // '%' <=> 0x25