Skip to content

Commit 5e1dbf5

Browse files
author
Nicholas C. Zakas
committed
Fixed faulty logic
1 parent 3b2e436 commit 5e1dbf5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

encodings/base64/base64.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function base64Encode(text){
8686

8787
//must encode one complete quanta at a time
8888
for(i=0; i < quantaCount; i++){
89-
for (j=0; j < 4; j++){
89+
for (j=0; j < 4 && bits.length; j++){
9090
part = bits.splice(0, 6).join("");
9191
index = parseInt(part,2);
9292
result.push(digits.charAt(index));
@@ -98,10 +98,12 @@ function base64Encode(text){
9898
case 8:
9999
padRight(bits, 12);
100100
padding = "==";
101+
quantaCount = 1;
101102
continue encodeBits;
102103
case 16:
103104
padRight(bits, 18);
104105
padding = "=";
106+
quantaCount = 1;
105107
continue encodeBits;
106108
default:
107109
break encodeBits;

0 commit comments

Comments
 (0)