From 96cc1ad55acd077f7e3ecc18685b7cee0cb58e18 Mon Sep 17 00:00:00 2001 From: Mikk Andresen Date: Fri, 5 May 2017 10:28:44 +0300 Subject: [PATCH 1/4] Use different cookie name for different protocols - https://github.com/ether/etherpad-lite/issues/3179 --- src/static/js/pad_cookie.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/static/js/pad_cookie.js b/src/static/js/pad_cookie.js index b563a7e6..72eb3fe9 100644 --- a/src/static/js/pad_cookie.js +++ b/src/static/js/pad_cookie.js @@ -23,6 +23,8 @@ var padcookie = (function() { + var cookieName = isHttpsScheme() ? "prefs" : "prefsHttp"; + function getRawCookie() { // returns null if can't get cookie text @@ -31,7 +33,7 @@ var padcookie = (function() return null; } // look for (start of string OR semicolon) followed by whitespace followed by prefs=(something); - var regexResult = document.cookie.match(/(?:^|;)\s*prefs=([^;]*)(?:;|$)/); + var regexResult = document.cookie.match(new RegExp("(?:^|;)\s*" + cookieName + "=([^;]*)(?:;|$)")); if ((!regexResult) || (!regexResult[1])) { return null; @@ -44,7 +46,7 @@ var padcookie = (function() var expiresDate = new Date(); expiresDate.setFullYear(3000); var secure = isHttpsScheme() ? ";secure" : ""; - document.cookie = ('prefs=' + safeText + ';expires=' + expiresDate.toGMTString() + secure); + document.cookie = (cookieName + "=" + safeText + ";expires=" + expiresDate.toGMTString() + secure); } function parseCookie(text) From 7790c5606bfb6fefb11aab8b00f2d7caecfa127a Mon Sep 17 00:00:00 2001 From: Mikk Andresen Date: Fri, 5 May 2017 10:54:26 +0300 Subject: [PATCH 2/4] Fix regexp --- src/static/js/pad_cookie.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static/js/pad_cookie.js b/src/static/js/pad_cookie.js index 72eb3fe9..f6ef1aa4 100644 --- a/src/static/js/pad_cookie.js +++ b/src/static/js/pad_cookie.js @@ -33,7 +33,7 @@ var padcookie = (function() return null; } // look for (start of string OR semicolon) followed by whitespace followed by prefs=(something); - var regexResult = document.cookie.match(new RegExp("(?:^|;)\s*" + cookieName + "=([^;]*)(?:;|$)")); + var regexResult = document.cookie.match(new RegExp("(?:^|;)\\s*" + cookieName + "=([^;]*)(?:;|$)")); if ((!regexResult) || (!regexResult[1])) { return null; From 582e2c3819bbecb41bad55b5a66ceb7b3bc3aaac Mon Sep 17 00:00:00 2001 From: Mikk Andresen Date: Fri, 5 May 2017 11:07:54 +0300 Subject: [PATCH 3/4] Use padcookie instead of raw prefs cookie reading --- src/static/js/pad.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static/js/pad.js b/src/static/js/pad.js index c967e461..0c825eeb 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -453,7 +453,7 @@ var pad = { // This will check if the prefs-cookie is set. // Otherwise it shows up a message to the user. padcookie.init(); - if (!readCookie("prefs")) + if (padcookie.wasNoCookie()) { $('#loading').hide(); $('#noCookie').show(); From c959cdbaa7a59ffe594710b2c86c369d55817385 Mon Sep 17 00:00:00 2001 From: Mikk Andresen Date: Fri, 5 May 2017 11:17:07 +0300 Subject: [PATCH 4/4] Pad_cookie.js to have isCookiesEnabled() cause wasNoCookie() is also true when User visits first time. --- src/static/js/pad.js | 2 +- src/static/js/pad_cookie.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/static/js/pad.js b/src/static/js/pad.js index 0c825eeb..9c3de091 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -453,7 +453,7 @@ var pad = { // This will check if the prefs-cookie is set. // Otherwise it shows up a message to the user. padcookie.init(); - if (padcookie.wasNoCookie()) + if (!padcookie.isCookiesEnabled()) { $('#loading').hide(); $('#noCookie').show(); diff --git a/src/static/js/pad_cookie.js b/src/static/js/pad_cookie.js index f6ef1aa4..62c88cff 100644 --- a/src/static/js/pad_cookie.js +++ b/src/static/js/pad_cookie.js @@ -124,6 +124,9 @@ var padcookie = (function() { return wasNoCookie; }, + isCookiesEnabled: function() { + return !!getRawCookie(); + }, getPref: function(prefName) { return cookieData[prefName];