Skip to content

Commit bedf873

Browse files
committed
CODEC-160 Base64.encodeBase64URLSafeString doesn't add padding characters at the end.
Javadoc updated to clarify this git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1396159 13f79535-47bb-0310-9956-ffa450edef68
1 parent ca5047c commit bedf873

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The <action> type attribute can be add,update,fix,remove.
4848
</release>
4949
-->
5050
<release version="1.8" date="TBA" description="Feature and fix release.">
51-
<action dev="..." type="fix" issue="CODEC-NNN">...</action>
51+
<action dev="sebb" type="fix" issue="CODEC-160">Base64.encodeBase64URLSafeString doesn't add padding characters at the end.</action>
5252
</release>
5353
<release version="1.7" date="11 September 2012" description="
5454
Feature and fix release.

src/main/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ public Base64(int lineLength, byte[] lineSeparator) {
261261
* @param urlSafe
262262
* Instead of emitting '+' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode
263263
* operations. Decoding seamlessly handles both modes.
264+
* <b>Note: no padding is added when using the URL-safe alphabet.</b>
264265
* @throws IllegalArgumentException
265266
* The provided lineSeparator included some base64 characters. That's not going to work!
266267
* @since 1.4
@@ -305,9 +306,10 @@ public boolean isUrlSafe() {
305306
/**
306307
* <p>
307308
* Encodes all of the provided data, starting at inPos, for inAvail bytes. Must be called at least twice: once with
308-
* the data to encode, and once with inAvail set to "-1" to alert encoder that EOF has been reached, so flush last
309+
* the data to encode, and once with inAvail set to "-1" to alert encoder that EOF has been reached, to flush last
309310
* remaining bytes (if not multiple of 3).
310311
* </p>
312+
* <p><b>Note: no padding is added when encoding using the URL-safe alphabet.</b></p>
311313
* <p>
312314
* Thanks to "commons" project in ws.apache.org for the bitwise operations, and general approach.
313315
* http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
@@ -567,7 +569,7 @@ public static String encodeBase64String(byte[] binaryData) {
567569
/**
568570
* Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The
569571
* url-safe variation emits - and _ instead of + and / characters.
570-
*
572+
* <b>Note: no padding is added.</b>
571573
* @param binaryData
572574
* binary data to encode
573575
* @return byte[] containing Base64 characters in their UTF-8 representation.
@@ -580,7 +582,7 @@ public static byte[] encodeBase64URLSafe(byte[] binaryData) {
580582
/**
581583
* Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The
582584
* url-safe variation emits - and _ instead of + and / characters.
583-
*
585+
* <b>Note: no padding is added.</b>
584586
* @param binaryData
585587
* binary data to encode
586588
* @return String containing Base64 characters
@@ -625,6 +627,7 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) {
625627
* if {@code true} this encoder will chunk the base64 output into 76 character blocks
626628
* @param urlSafe
627629
* if {@code true} this encoder will emit - and _ instead of the usual + and / characters.
630+
* <b>Note: no padding is added when encoding using the URL-safe alphabet.</b>
628631
* @return Base64-encoded data.
629632
* @throws IllegalArgumentException
630633
* Thrown when the input array needs an output array bigger than {@link Integer#MAX_VALUE}
@@ -643,6 +646,7 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean
643646
* if {@code true} this encoder will chunk the base64 output into 76 character blocks
644647
* @param urlSafe
645648
* if {@code true} this encoder will emit - and _ instead of the usual + and / characters.
649+
* <b>Note: no padding is added when encoding using the URL-safe alphabet.</b>
646650
* @param maxResultSize
647651
* The maximum result size to accept.
648652
* @return Base64-encoded data.

0 commit comments

Comments
 (0)