From d3b6f63e5bc27215fa75f9e434a7a8dfb7cbfd26 Mon Sep 17 00:00:00 2001 From: Amauri CHAMPEAUX Date: Thu, 20 May 2021 18:59:08 +0200 Subject: [PATCH] Check if cookie exist before purge --- tarteaucitron.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tarteaucitron.js b/tarteaucitron.js index 31367cb..f3821de 100644 --- a/tarteaucitron.js +++ b/tarteaucitron.js @@ -1534,9 +1534,13 @@ var tarteaucitron = { var i; for (i = 0; i < arr.length; i += 1) { - document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/;'; - document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname + ';'; - document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname.split('.').slice(-2).join('.') + ';'; + + var rgxpCookie = new RegExp("^(.*;)?\\s*" + arr[i] + "\\s*=\\s*[^;]+(.*)?$"); + if (document.cookie.match(rgxpCookie)) { + document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/;'; + document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname + ';'; + document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname.split('.').slice(-2).join('.') + ';'; + } } }, "checkCount": function (key) {