Skip to content

Commit a93c88e

Browse files
committed
fix: decode logic
1 parent 0198b78 commit a93c88e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/shared/src/utils/base64.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ export function base64Decode(str: string) {
1818
const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
1919
let result = ''
2020
let i = 0
21-
do {
21+
while (i < str.length) {
2222
const a = base64Chars.indexOf(str[i++])
2323
const b = base64Chars.indexOf(str[i++])
2424
const c = base64Chars.indexOf(str[i++])
2525
const d = base64Chars.indexOf(str[i++])
2626
result += String.fromCharCode(a << 2 | b >> 4)
27-
c !== 64 && (result += String.fromCharCode(b << 4 | c >> 2))
28-
d !== 64 && (result += String.fromCharCode(c << 6 | d))
29-
} while (i < str.length)
27+
if (c !== -1)
28+
result += String.fromCharCode((b & 15) << 4 | c >> 2)
29+
if (d !== -1)
30+
result += String.fromCharCode((c & 3) << 6 | d)
31+
}
3032
return result
3133
}

0 commit comments

Comments
 (0)