Problem/Motivation

Disabling scripts assigned to specific category does not work. I want to
disable the script of a module and allow the script, if the user consents to a
specific category. Therefore I put something like
examplecat:sites/all/modules/example/example.js into the "Disable
JavaScripts" textbox. However, the script still gets loaded even if the user
does not consent to the specific category.

Steps to reproduce

  1. Use "Opt-in with categories" as consent method.
  2. Create a new category
  3. Look up the path of a script that should be disabled, unless consent
    for the category is given.
  4. Load a page on which the script is loaded and do not give consent to
    the above category. The script will still get executed.

Proposed resolution

There is a bug in eu_cookie_compliance_js_alter(). The code checks, if the
script exists in the array of all scripts. It does so by comparing the lines
from the "Disable JavaScripts" text area with the path of the attached
javascript files before removing the category (and behavior) from the input
lines. The correct thing would be to strip the category and behavior from the
line, before comparing.

A patch to solve the issue is attached.

Comments

lukas_w created an issue. See original summary.

svenryen’s picture

Thanks for the report. I'll take a look.

poker10’s picture

Status: Active » Needs review

I can confirm this bug, we have are experiencing it. As mentioned in the IS, the problem is that the array_key_exists compares the script path with the JS array before the category is removed:

if (array_key_exists($script, $javascript)) {
  // Remove 'category:' if present.
  ..
}

So instead of looking for sites/all/modules/example/example.js it will look for examplecat:sites/all/modules/example/example.js and this will not be found in the JS array and thus not unset.

Thanks for working on this! Should this be Needs review?

  • svenryen committed 02354235 on 7.x-1.x authored by lukas_w
    Issue #3317344 by lukas_w, svenryen, poker10: Disabling scripts with...
svenryen’s picture

Status: Needs review » Fixed

Thanks for the patch and the RTBC.

Status: Fixed » Closed (fixed)

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