Skip to content

Commit 2923828

Browse files
committed
fix: base64.py 'Incorrect padding' error
Update python implementation of 'atob' to properly reflect behaviour of JS 'atob'.
1 parent 5fc6ce0 commit 2923828

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

python/pythonmonkey/builtin_modules/base64.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99

1010
def atob(b64):
11-
return str(base64.standard_b64decode(b64), 'latin1')
11+
# Workaround for pythons 'Incorrect padding' error when base64 decoding, see:
12+
# https://stackoverflow.com/questions/2941995/python-ignore-incorrect-padding-error-when-base64-decoding
13+
append = b"==" if isinstance(b64, bytes) else "=="
14+
return str(base64.standard_b64decode(b64 + append), 'latin1')
1215

1316

1417
def btoa(data):

0 commit comments

Comments
 (0)