Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Prevent JSON.parse to be called with a non string value (#400)
Browse files Browse the repository at this point in the history
Co-authored-by: joaoaraujo-hotmart <[email protected]>
  • Loading branch information
joaoaraujo-hotmart and joaoaraujo-hotmart committed Sep 21, 2021
1 parent 7d07329 commit 6b5c2db
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export default function <State>(
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;
Expand Down

0 comments on commit 6b5c2db

Please sign in to comment.