From 6b5c2db5c44b171b8ef050047e53bafb33f9935e Mon Sep 17 00:00:00 2001 From: joaoaraujo-hotmart Date: Tue, 21 Sep 2021 08:31:54 -0300 Subject: [PATCH] Prevent JSON.parse to be called with a non string value (#400) Co-authored-by: joaoaraujo-hotmart --- src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index f375913..1e82f73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,9 +38,9 @@ export default function ( const value = storage.getItem(key); try { - return (typeof value !== "undefined") - ? JSON.parse(value) - : undefined; + return (typeof value === "string") + ? JSON.parse(value) : (typeof value === "object") + ? value : undefined; } catch (err) {} return undefined;