Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/commons/codec/binary/Base32.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Builder setEncodeTable(final byte... encodeTable) {
}

/**
* 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>
Expand All @@ -113,7 +113,7 @@ public Builder setEncodeTable(final byte... encodeTable) {
* @since 1.18.0
*/
public Builder setHexDecodeTable(final boolean useHex) {
return setEncodeTable(decodeTable(useHex));
return setEncodeTable(encodeTable(useHex));
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/apache/commons/codec/binary/Base32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ void testBase32HexImpossibleSamples() {
// @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);
Expand Down
Loading