This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git
The following commit(s) were added to refs/heads/master by this push:
new 75915042 [CODEC-343] Fix Base32 hex decode table builder (#435)
75915042 is described below
commit 759150423e3a51adf095ebf770d82f3183f8a9cb
Author: OldTruckDriver <[email protected]>
AuthorDate: Thu Jun 18 12:02:43 2026 +1000
[CODEC-343] Fix Base32 hex decode table builder (#435)
Configure setHexDecodeTable(boolean) with the matching encode table instead
of passing a decode lookup table to setEncodeTable(byte...).
Add a regression test showing the configured codec encodes with the
Base32-Hex alphabet and decodes its own output.
Reviewed-by: OpenAI Codex
Reviewed-by: Anthropic Claude Code
Co-authored-by: Gary Gregory <[email protected]>
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/codec/binary/Base32.java | 4 ++--
src/test/java/org/apache/commons/codec/binary/Base32Test.java | 9 +++++++++
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f43f0329..3763d0b8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -45,6 +45,7 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="1.22.1" date="YYYY-MM-DD" description="This is a feature
and maintenance release. Java 8 or later is required.">
<!-- FIX -->
+ <action type="fix" issue="CODEC-343" dev="ggregory" due-to="Ruiqi Dong,
Gary Gregory">Base32.Builder.setHexDecodeTable(boolean) sets the encode table
to a decode lookup table.</action>
<action type="fix" issue="CODEC-341" dev="ggregory" due-to="Ruiqi Dong,
Gary Gregory">Base16.Builder.setEncodeTable(byte...) can create a codec that
cannot decode its own output.</action>
<action type="fix" issue="CODEC-339" dev="ggregory" due-to="Ruiqi Dong,
Gary Gregory">URLCodec.encodeUrl(BitSet, byte[]) allows custom safe sets to
emit URL encoding control characters.</action>
<action type="fix" issue="CODEC-338" dev="ggregory" due-to="Ruiqi Dong,
Gary Gregory">PercentCodec loses literal '+' when plusForSpace is
enabled.</action>
diff --git a/src/main/java/org/apache/commons/codec/binary/Base32.java
b/src/main/java/org/apache/commons/codec/binary/Base32.java
index 1de64238..a1206c67 100644
--- a/src/main/java/org/apache/commons/codec/binary/Base32.java
+++ b/src/main/java/org/apache/commons/codec/binary/Base32.java
@@ -103,7 +103,7 @@ public class Base32 extends BaseNCodec {
}
/**
- * Sets the decode table to use Base32 hexadecimal if {@code true},
otherwise use the Base32 alphabet.
+ * Sets the encode and decode tables to use Base32 hexadecimal if
{@code true}, otherwise use the Base32 alphabet.
* <p>
* This overrides a value previously set with {@link
#setEncodeTable(byte...)}.
* </p>
@@ -113,7 +113,7 @@ public class Base32 extends BaseNCodec {
* @since 1.18.0
*/
public Builder setHexDecodeTable(final boolean useHex) {
- return setEncodeTable(decodeTable(useHex));
+ return setEncodeTable(encodeTable(useHex));
}
/**
diff --git a/src/test/java/org/apache/commons/codec/binary/Base32Test.java
b/src/test/java/org/apache/commons/codec/binary/Base32Test.java
index c332c448..ed3e0b9c 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base32Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base32Test.java
@@ -319,6 +319,15 @@ class Base32Test {
// @formatter:on
}
+ @Test
+ void testBuilderSetHexDecodeTableDecodesOwnOutput() {
+ final Base32 base32 =
Base32.builder().setHexDecodeTable(true).setLineLength(0).get();
+ final byte[] data = { 0 };
+ final byte[] encoded = base32.encode(data);
+ assertEquals("00======", new String(encoded,
StandardCharsets.US_ASCII));
+ assertArrayEquals(data, base32.decode(encoded));
+ }
+
@Test
void testBase32HexSamples() throws Exception {
final Base32 codec = new Base32(true);