Skip to content

Commit

Permalink
update - URIComponent just for cookie value
Browse files Browse the repository at this point in the history
  • Loading branch information
MHSanaei committed May 22, 2023
1 parent 66e3c50 commit ffa23a4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions web/assets/js/util/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,27 @@ function debounce(fn, delay) {

function getCookie(cname) {
let name = cname + '=';
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
let ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
// decode cookie value only
return decodeURIComponent(c.substring(name.length, c.length));
}
}
return '';
}


function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
let expires = 'expires=' + d.toUTCString();
document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/';
// encode cookie value
document.cookie = cname + '=' + encodeURIComponent(cvalue) + ';' + expires + ';path=/';
}

function usageColor(data, threshold, total) {
Expand Down

0 comments on commit ffa23a4

Please sign in to comment.