TiddlyWiki: bugfix for Firefox Quantum -- use HTML5 web storage instead of a Cookie

Firefox Quantum adopted the idiotic behaviour of Chrome and does no longer
retrieve Cookies for pages read from local file system. It stores the Cookie
data into its local cookies.sqlite, but it does not retrieve it anymore.
For aledged "security reasons", however it happily retrieves HTML 5 web storage

Since TiddlyWiki classic just accesses the document.cookie at 3 points,
it is easy to patch around that problem. Just check, if we're using a modern
browser with support for HTML5 web storage and branch accordingly.
This commit is contained in:
Fischlurch 2018-10-20 02:07:10 +02:00
parent 7e562a4c66
commit 72974f2548
2 changed files with 56 additions and 8 deletions

View file

@ -6261,6 +6261,16 @@ var loadOptionsCookie = loadOptions;
function getCookies()
{
if (typeof(Storage) !== "undefined") {
// modern browser: use HTML5 web storage
var storedData = {};
for (var n = window.localStorage.length || 0; --n >= 0; ) {
var key = window.localStorage.key(n);
storedData[key] = window.localStorage[key];
}
return storedData;
}
// else: use old-style cookie storage
var cookieList = document.cookie.split(';');
var i,cookies = {};
for(i=0; i<cookieList.length; i++) {
@ -6325,8 +6335,14 @@ var saveOptionCookie = saveOption;
function removeCookie(name)
{
if (typeof(Storage) !== "undefined") {
// modern browser: use HTML5 web storage
window.localStorage.removeItem(name);
} else {
// use old-style cookie storage
document.cookie = name + '=; expires=Thu, 01-Jan-1970 00:00:01 UTC; path=/;';
}
}
function saveCookie(name)
{
@ -6336,10 +6352,18 @@ function saveCookie(name)
value = value == null ? 'false' : value;
cookies[key] = value;
}
var encodedCookie = String.encodeHashMap(cookies).replace(/%/g,'%25').replace(/"/g,'%22')
// Modern browsers (e.g. Firefox Quantum) do not support Cookies for file:/// anymore
if (typeof(Storage) !== "undefined") {
// modern browser: use HTML5 web storage
window.localStorage.TiddlyWikiClassicOptions = encodedCookie;
} else {
// use old-style cookie storage
// TW291 and later (#159)
document.cookie = 'TiddlyWikiClassicOptions='
+ String.encodeHashMap(cookies).replace(/%/g,'%25').replace(/"/g,'%22')
+ encodedCookie
+ '; expires=Fri, 1 Jan 2038 12:00:00 UTC; path=/';
}
cookies = getCookies();
var c;
for(c in cookies) {

View file

@ -16006,6 +16006,16 @@ var loadOptionsCookie = loadOptions;
function getCookies()
{
if (typeof(Storage) !== "undefined") {
// modern browser: use HTML5 web storage
var storedData = {};
for (var n = window.localStorage.length || 0; --n >= 0; ) {
var key = window.localStorage.key(n);
storedData[key] = window.localStorage[key];
}
return storedData;
}
// else: use old-style cookie storage
var cookieList = document.cookie.split(';');
var i,cookies = {};
for(i=0; i<cookieList.length; i++) {
@ -16070,8 +16080,14 @@ var saveOptionCookie = saveOption;
function removeCookie(name)
{
if (typeof(Storage) !== "undefined") {
// modern browser: use HTML5 web storage
window.localStorage.removeItem(name);
} else {
// use old-style cookie storage
document.cookie = name + '=; expires=Thu, 01-Jan-1970 00:00:01 UTC; path=/;';
}
}
function saveCookie(name)
{
@ -16081,10 +16097,18 @@ function saveCookie(name)
value = value == null ? 'false' : value;
cookies[key] = value;
}
var encodedCookie = String.encodeHashMap(cookies).replace(/%/g,'%25').replace(/"/g,'%22')
// Modern browsers (e.g. Firefox Quantum) do not support Cookies for file:/// anymore
if (typeof(Storage) !== "undefined") {
// modern browser: use HTML5 web storage
window.localStorage.TiddlyWikiClassicOptions = encodedCookie;
} else {
// use old-style cookie storage
// TW291 and later (#159)
document.cookie = 'TiddlyWikiClassicOptions='
+ String.encodeHashMap(cookies).replace(/%/g,'%25').replace(/"/g,'%22')
+ encodedCookie
+ '; expires=Fri, 1 Jan 2038 12:00:00 UTC; path=/';
}
cookies = getCookies();
var c;
for(c in cookies) {