-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cookies.js uses deprecated escape and unescape functions #438
Comments
I took this I'm still in favor of using this kind of small framework to handle cookies. It's true that we don't currently use a lot of cookies. But, as you experienced, there can be many little traps we can fall into. If the cookie handling is in one-liners all over the code, it makes it less readable ( I'd vote to fix this version of |
No problem, I'm fine with fixing the framework! It's small, it's not problem to keep it, and the fix looks easy. |
You can see the use of these in
cookies.js
here: https://github.com/kiwix/kiwix-js/blob/master/www/js/lib/cookies.js#L26See the big red warning sign regarding
escape-unescape
on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape .This is causing me some problems with UTF-8 characters in document titles in an experimental branch where I encode the last-visited page title in a cookie. It seems that
escape-unescape
are pre-UTF8 era, and we should useencodeURIComponent
anddecodeURIComponent
instead where we are not using simple ASCII.We don't need a framework for our limited handling of cookies. because it's very easy to get and set them without a framework, since a) we set the values ourselves, so we control them; b) most (all?) of the key-value pairs we use are ASCII; and c) if we extend them in the future we can simply
encodeURIComponent
anddecodeURIComponent
anything else ourselves.These are the only patterns we need in our current code, I think, and they're one-liners:
Getting the value of
lastContentInjectionMode
:value = document.cookie.replace(/^.*lastContentInjectionMode=([^;]*).*$/, '$1');
Setting the value of
lastContentInjectionMode
:document.cookie = 'lastContentInjectionMode=' + lastContentInjectionMode + ';expires=Fri, 31 Dec 9999 23:59:59 GMT';
And for good measure, though I don't think we use these patterns:
Checking that value of
myKey
istrue
:if (/myKey=true\b/i.test(document.cookie) { do something }
Deleting
myKey
:document.cookie = myKey + '=;expires=Thu, 21 Sep 1979 00:00:01 UTC';
The text was updated successfully, but these errors were encountered: