Skip to content

Commit dc3af23

Browse files
committed
Update angular-base64.js
Automatically pad out decode string size with '=' or '==' for compatibility with encoders which do not automatically add padding. See: ninjatronic#13
1 parent 681f305 commit dc3af23

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

angular-base64.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,18 @@
7171
function decode(s) {
7272
// convert to string
7373
s = "" + s;
74-
var pads, i, b10;
75-
var imax = s.length;
74+
var pads, i, b10, imax;
75+
76+
if ((s.length % 4) === 1) {
77+
s = s + PADCHAR;
78+
}
79+
80+
if ((s.length % 4) === 2) {
81+
s = s + PADCHAR + PADCHAR;
82+
}
83+
84+
imax = s.length;
85+
7686
if (imax == 0) {
7787
return s;
7888
}

0 commit comments

Comments
 (0)