diff --git a/js/cookieContentBlocker.js b/js/cookieContentBlocker.js index d86ad7f..ae5eee5 100644 --- a/js/cookieContentBlocker.js +++ b/js/cookieContentBlocker.js @@ -46,12 +46,21 @@ * Whether or not we have a cookie value match. */ var matchCookieValue = function (cookieMatch) { + // Make sure the name of the cookie and the value to compare against is set. + if (typeof cookieMatch.name !== 'string' && typeof cookieMatch.value !== 'string') { + return false; + } + + // Load the current value of the cookie. var currentValue = $.cookie(cookieMatch.name); - if (currentValue === null || currentValue === void (0) || typeof cookieMatch.value !== 'string') { - return false; + // Handle special case when the cookie is not set. + if (currentValue === null || currentValue === void (0)) { + // Handle special case of 'not exists' operator. + return cookieMatch.operator === '!e' } + // Create a map for the rest of the operators. var matchMap = { 'e': function () { return true; @@ -67,9 +76,13 @@ }, 'c': function (v) { return currentValue.includes(v); + }, + '!c': function (v) { + return !currentValue.includes(v); } }; + // If the operator is set, do the comparison. return (matchMap[cookieMatch.operator] !== void (0) && matchMap[cookieMatch.operator](cookieMatch.value) || false); }; diff --git a/src/Form/BlockerSettingsForm.php b/src/Form/BlockerSettingsForm.php index 2d20b2d..10872f2 100644 --- a/src/Form/BlockerSettingsForm.php +++ b/src/Form/BlockerSettingsForm.php @@ -154,7 +154,9 @@ class BlockerSettingsForm extends ConfigFormBase { '>' => $this->t('Greater than'), '<' => $this->t('Less than'), 'c' => $this->t('Contains'), + '!c' => $this->t('Not contains'), 'e' => $this->t('Exists'), + '!e' => $this->t('Not exists'), ]; }