From fb92e2171171580c590025497dc2229160b2d04f Mon Sep 17 00:00:00 2001 From: kira924age Date: Thu, 21 Dec 2023 20:53:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20update=20decodePayload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 3cb4bcb..5f9371d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -198,7 +198,12 @@ async function importKey(key: string | JsonWebKey, algorithm: SubtleCryptoImport function decodePayload(raw: string): T | undefined { try { - return JSON.parse(atob(raw)) + const binaryString = atob(raw) + const encodedString = encodeURIComponent(binaryString).replace(/%([0-9A-F]{2})/g, (match, p1) => { + return String.fromCharCode('0x' + p1); + }); + + return JSON.parse(decodeURIComponent(encodedString)); } catch { return }