From c28ba78c72dd1ae19a99906eda4128d1c7afc3a4 Mon Sep 17 00:00:00 2001 From: Orest Bida Date: Fri, 8 Oct 2021 23:45:11 +0200 Subject: [PATCH 1/4] encode cookie value using `encodeUriComponent` instead of `btoa` (base64) --- src/cookieconsent.js | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/cookieconsent.js b/src/cookieconsent.js index 55cda890..b7b0c8eb 100644 --- a/src/cookieconsent.js +++ b/src/cookieconsent.js @@ -1673,7 +1673,7 @@ */ var _setCookie = function(name, value) { - var value = _config.use_rfc_cookie ? b64EncodeUnicode(value) : value; + var value = _config.use_rfc_cookie ? encodeURIComponent(value) : value; var date = new Date(); date.setTime(date.getTime() + (1000 * ( _config.cookie_expiration * 24 * 60 * 60))); @@ -1715,7 +1715,7 @@ try{ found = JSON.parse(found) }catch(e){ - found = JSON.parse(b64DecodeUnicode(found)) + found = JSON.parse(decodeURIComponent(found)) } found = JSON.stringify(found); } @@ -1796,30 +1796,6 @@ } } - /** - * Encoding UTF8 -> base64 - * https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings - * @param {string} str - * @returns {string} - */ - function b64EncodeUnicode(str) { - return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) { - return String.fromCharCode(parseInt(p1, 16)) - })) - } - - /** - * Decoding base64 -> UTF8 - * https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings - * @param {string} str - * @returns {string} - */ - function b64DecodeUnicode(str) { - return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) { - return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2) - }).join('')) - } - /** * Append class to the specified dom element * @param {HTMLElement} elem From 55ac287cc34f94bf570789dae890344997a99708 Mon Sep 17 00:00:00 2001 From: Orest Bida Date: Fri, 8 Oct 2021 23:49:02 +0200 Subject: [PATCH 2/4] fix a11y issue caused by `.set(revision)` --- src/cookieconsent.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/cookieconsent.js b/src/cookieconsent.js index b7b0c8eb..b2621184 100644 --- a/src/cookieconsent.js +++ b/src/cookieconsent.js @@ -260,7 +260,7 @@ } } - var _conf_params, _createConsentModal, revision_message=""; + var _conf_params, _createConsentModal, revision_message="", consent_text; /** * Generate cookie consent html based on config settings @@ -291,12 +291,27 @@ if(conf_params['force_consent'] === true){ _addClass(html_dom, 'force--consent'); } + + var description = conf_params.languages[lang]['consent_modal']['description']; + + if(revision_enabled){ + if(!valid_revision){ + description = description.replace("{{revision_message}}", revision_message || conf_params.languages[lang]['consent_modal']['revision_message'] || ""); + }else{ + description = description.replace("{{revision_message}}", ""); + } + } + + if(consent_modal){ + consent_text.innerHTML = description; + return; + } consent_modal = _createNode('div'); var consent_modal_inner = _createNode('div'); var consent_modal_inner_inner = _createNode('div'); var consent_title = _createNode('div'); - var consent_text = _createNode('div'); + consent_text = _createNode('div'); var consent_buttons = _createNode('div'); var consent_primary_btn = _createNode('button'); var consent_secondary_btn = _createNode('button'); @@ -331,16 +346,6 @@ // Use insertAdjacentHTML instead of innerHTML consent_title.insertAdjacentHTML('beforeend', conf_params.languages[lang]['consent_modal']['title']); - var description = conf_params.languages[lang]['consent_modal']['description']; - - if(revision_enabled){ - if(!valid_revision){ - description = description.replace("{{revision_message}}", revision_message || conf_params.languages[lang]['consent_modal']['revision_message'] || ""); - }else{ - description = description.replace("{{revision_message}}", ""); - } - } - consent_text.insertAdjacentHTML('beforeend', description); consent_primary_btn[innerText] = conf_params.languages[lang]['consent_modal']['primary_btn']['text']; @@ -1396,7 +1401,6 @@ // If plugin has been initialized and new revision is valid if( main_container - && cookie_consent_accepted && typeof new_revision === "number" && saved_cookie_content['revision'] !== new_revision ){ @@ -1408,11 +1412,9 @@ // Show consent modal ? if(prompt_consent === true){ - if(!consent_modal_exists){ - _createConsentModal(_conf_params); - _guiManager(_conf_params['gui_options'], true); - } - + _createConsentModal(_conf_params); + _guiManager(_conf_params['gui_options'], true); + _getModalFocusableData(); _cookieconsent.show(); }else { // If revision was modified, save cookie with the new revision From dbc7479767fab6448c2029e688feb25cdc6ba830 Mon Sep 17 00:00:00 2001 From: Orest Bida Date: Fri, 8 Oct 2021 23:49:33 +0200 Subject: [PATCH 3/4] update version number to v2.6.1 --- src/cookieconsent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cookieconsent.js b/src/cookieconsent.js index b2621184..26c931b6 100644 --- a/src/cookieconsent.js +++ b/src/cookieconsent.js @@ -1,5 +1,5 @@ /*! - * CookieConsent v2.6.0 + * CookieConsent v2.6.1 * https://www.github.com/orestbida/cookieconsent * Author Orest Bida * Released under the MIT License From b8a6fb977cb33929ea4a7fe91787cedf51f58a8b Mon Sep 17 00:00:00 2001 From: Orest Bida Date: Fri, 8 Oct 2021 23:53:18 +0200 Subject: [PATCH 4/4] release dist version :bookmark: --- dist/cookieconsent.js | 66 +++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/dist/cookieconsent.js b/dist/cookieconsent.js index 6e724424..f963aac5 100644 --- a/dist/cookieconsent.js +++ b/dist/cookieconsent.js @@ -1,38 +1,38 @@ /* - CookieConsent v2.6.0 + CookieConsent v2.6.1 https://www.github.com/orestbida/cookieconsent Author Orest Bida Released under the MIT License */ -(function(){function Wa(Xa){function Ga(a,b){return a.classList?a.classList.contains(b):!!a.className.match(new RegExp("(\\s|^)"+b+"(\\s|$)"))}function ta(a,b){a.classList?a.classList.remove(b):a.className=a.className.replace(new RegExp("(\\s|^)"+b+"(\\s|$)")," ")}function F(a,b){a.classList?a.classList.add(b):Ga(a,b)||(a.className+=" "+b)}function ha(a){if("object"===typeof a){var b=[],c=0;for(b[c++]in a);return b}}function G(a,b,c,d){a.addEventListener?d?a.addEventListener(b,c,{passive:!0}):a.addEventListener(b, -c,!1):a.attachEvent("on"+b,c)}function Ha(a,b,c){b=b?b:"/";for(var d=0;d
\x3c!--\x3e
\x3c!--
\x3c!--\x3e
\x3c!--