From 3fd594bbb5d666f806fb4f69ed1d0a483c6dbd67 Mon Sep 17 00:00:00 2001 From: kira924age Date: Thu, 21 Dec 2023 21:28:29 +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 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3ab92b4..e1e256b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -199,11 +199,15 @@ async function importKey(key: string | JsonWebKey, algorithm: SubtleCryptoImport function decodePayload(raw: string): T | undefined { try { const binaryString = atob(raw) - const encodedString = encodeURIComponent(binaryString).replace(/%([0-9A-F]{2})/g, (_match, p1) => { - return String.fromCharCode(parseInt(p1, 16)); - }); + const bytes = new Uint8Array(binaryString.length); + for (let i = 0; i < binaryString.length; i++) { + bytes[i] = binaryString.charCodeAt(i); + } - return JSON.parse(decodeURIComponent(encodedString)); + const decoder = new TextDecoder('utf-8'); + const decodedString = decoder.decode(bytes); + + return JSON.parse(decodedString); } catch { return }