Skip to content

Commit 5f1a47b

Browse files
committed
non json cookie bug fix
1 parent 4b904cf commit 5f1a47b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/js/api.plugin.cookie.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ Cookies.setJSON = function (cookieName, data, cookieOptions) {
66
Cookies.set(cookieName, JSON.stringify(data), cookieOptions);
77
}
88

9-
109
Cookies.getJSON = function (cookieName) {
1110
var cookieValue = Cookies.get(cookieName);
1211
if (cookieValue) {
13-
return JSON.parse(cookieValue)
12+
try {
13+
return JSON.parse(cookieValue)
14+
} catch (error) {
15+
Cookies.remove(cookieName);
16+
console.warn(["invalid cookie removed", cookieName, error])
17+
return null;
18+
}
19+
1420
}
1521
else {
1622
return cookieValue

src/js/api.plugin.cookie.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)