Problem/Motivation

I have a site that uses eu_c_c 1.36.

It is set to automatically delete cookies if consent is not given.

While the popup is displaying, and if I choose not to give consent, I see this JS error consistently, in both Edge and Chrome:

Uncaught TypeError: pattern.indexOf is not a function
    at Function.Drupal.eu_cookie_compliance.cookieMatches (eu_cookie_compliance.js?qltg60:777)
    at Function.Drupal.eu_cookie_compliance.isAllowed (eu_cookie_compliance.js?qltg60:804)
    at Drupal.eu_cookie_compliance.BlockCookies (eu_cookie_compliance.js?qltg60:932)

The error goes away if I turn off automatic cookie deletion.

Unfortunately, I need automatic cookie deletion. :-)

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Mile23 created an issue. See original summary.

mile23’s picture

Version: 7.x-1.36 » 7.x-1.x-dev
StatusFileSize
new2.21 KB

When I add some logging to show what's being passed to cookieMatches(), I see this:

eu_cookie_compliance.js?qlux4h:804 
eu_cookie_compliance.js?qlux4h:804 cookie-agreed
eu_cookie_compliance.js?qlux4h:804 cookie-agreed-categories
eu_cookie_compliance.js?qlux4h:804 cookie-agreed-version
eu_cookie_compliance.js?qlux4h:804 ƒ (){for(var e,t,i=this.length;i;e=Math.floor(Math.random()*i),t=this[--i],this[i]=this[e],this[e]=t);return this}

So the first one is because there are no allowed cookies configured. The middle ones make sense. That last one however...

So we ignore functions by defensively checking for strings.

    // Check if the cookie is allowed.
    for (const item in euCookieComplianceAllowlist) {
      // Defensively check types for comparison.
      if (typeof euCookieComplianceAllowlist[item] === "string") {
        if (Drupal.eu_cookie_compliance.cookieMatches(cookieName, euCookieComplianceAllowlist[item])) {
          return true;
        }
[..etc..]

I'm far from a JavaScript expert, so there might be a better solution.

Here's a patch against 7.x-1.x.

mile23’s picture

Status: Active » Needs review
mile23’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Needs review » Needs work

It turns out this issue applies to 8.x-1.x as well.

The patch in #2 does not apply to 8.x-1.x, but can be easily reproduced for it.

suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new2.46 KB

Patch against 8.x-1.x. Please review.

Status: Needs review » Needs work

The last submitted patch, 5: 3189737-5.patch, failed testing. View results

svenryen’s picture

Status: Needs work » Needs review

svenryen’s picture

StatusFileSize
new2.46 KB

Fixed Drupal.settings => drupalSettings in the d8 patch.

  • svenryen committed fd0b6ca on 8.x-1.x
    Issue #3189737 by Mile23, svenryen, Suresh Prabhu Parkala: JS errors for...
svenryen’s picture

Status: Needs review » Fixed

Applied and tested - thanks for the patches!

  • svenryen committed 415c934 on 7.x-2.x authored by Suresh Prabhu Parkala
    Issue #3189737 by Mile23, Suresh Prabhu Parkala, svenryen: JS errors for...
  • svenryen committed df4e221 on 7.x-2.x
    Merge branch '7.x-1.x' into 7.x-2.x
    
    * 7.x-1.x:
      Issue #3206637 by...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.