[NET] Changed behavior in deprecated Base64.decode.
Alexander Scheibe <[email protected]> Thu, 19 Sep 2024 12:33:24 +0000
| Newsgroups | gmane.comp.jakarta.commons.user |
|---|---|
| Message-ID | <FR2P281MB241219534F4BAB1248E899B6FA632@FR2P281MB2412.DEUP281.PROD.OUTLOOK.COM> |
With 3.11.x the behavior for Base64.decode changed, previously it would seamlessly handle both urlSafe and standard modes.
As still documented in the constructor Base64(int lineLength, byte[] lineSeparator, final boolean urlSafe)
"@param urlSafe Instead of emitting '+' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode operations. Decoding seamlessly handles both modes."
The following now throws IllegalArgumentException: Illegal base64 character 2d
boolean urlSafe = false;
String encoded = "o6wBF2p1dwkzJbXY+vUaAg==";
final byte[] bytesToEncode = new Base64(0, new byte[] {}, false).decode(encoded);
urlSafe = true;
String encodedUrlSafe = new Base64(0, new byte[] {}, true).encodeToString(bytesToEncode);
final byte[] decoded = new Base64(0, new byte[] {}, false).decode(encodedUrlSafe);
Revisions before this commit still have the expected behavior: https://github.com/apache/commons-net/commit/deb24bf22b1f75e4dc1bc981f2bcd37f5c407ceb
Although Base64 is deprecated, its behavior should not change.
Thanks,
Alexander