use better mechanism for base64 decoding with unicode characters (#172445)

Fixes #172441
This commit is contained in:
Tyler James Leonhardt 2023-01-25 12:32:00 -08:00 committed by GitHub
parent 88e4667480
commit 7fc1f6aacb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,10 @@ export function base64Encode(text: string): string {
}
export function base64Decode(text: string): string {
const data = atob(text);
return data;
// modification of https://stackoverflow.com/a/38552302
const replacedCharacters = text.replace(/-/g, '+').replace(/_/g, '/');
const decodedText = decodeURIComponent(atob(replacedCharacters).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return decodedText;
}