Problem/Motivation

I was getting the following error on updating the module from version 1.14 to 1.16

Uncaught SyntaxError: Unexpected token % in JSON at position 0
    at JSON.parse (<anonymous>)
    at Function.Drupal.eu_cookie_compliance.getAcceptedCategories (eu_cookie_compliance.js?v=9.2.6:629)
    at HTMLBodyElement.<anonymous> (eu_cookie_compliance.js?v=9.2.6:29)

Clearing the cookies resolved the issue.
When I set the cookies again I noticed that the cookie value of 'cookie-agreed-categories' has changed. The cookie value is not URL encoded now.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Jeslin.Shaji created an issue. See original summary.

ivnish’s picture

Is it actual for 1.18 ?

svenryen’s picture

@Jeslin.Shaji, what's your cookie value? and are the machine names of your categories?

jeslin.shaji’s picture

StatusFileSize
new45.11 KB
new40.97 KB

@svenryen, I have 2 cookie categories with machine names - necessary_cookies and statistics_cookies.
The cookie value of 'cookie-agreed-categories' was %5B%22necessary_cookies%22%2C%22statistics_cookies%22%5D
The new value is ["necessary_cookies","statistics_cookies"].
Attaching screenshots of these.

svenryen’s picture

Thanks, will be taking a look this weekend. The change in formatting was not intentional.

svenryen’s picture

This is caused by the move from jQuery Cookie to Js-cookie. We need to encode the string that Js-cookie saves so that it matches the previous one from jQuery Cookie.

I'll make a fix for this tomorrow.

svenryen’s picture

A fix is in the issue branch.

For those who want a patch file: https://git.drupalcode.org/project/eu-cookie-compliance/-/merge_requests...

  • svenryen committed 28c3ac4 on 8.x-1.x
    Issue #3241333 by svenryen, Jeslin.Shaji: Uncaught SyntaxError:...
svenryen’s picture

Status: Active » Fixed
onedotover’s picture

Hi there. I'm sorry this isn't in the form of a patch. The escape replacement needs to be changed to a regex so it replaces all instances not just the first one. It needs to be:

      // JS cookie introduced unescaped cookie values.
      if (storedCategories.indexOf('%') !== -1) {
        storedCategories = decodeURI(storedCategories).replace(/%2C/g, ',');
      }
svenryen’s picture

Thanks, @onedotover, I'll take a look.

svenryen’s picture

Status: Fixed » Needs review

  • svenryen committed 1872286 on 8.x-1.x authored by onedotover
    Issue #3241333 by svenryen, Jeslin.Shaji, onedotover: Uncaught...
svenryen’s picture

Status: Needs review » Fixed

Reviewed and tested. Thanks for contributing! :)

Status: Fixed » Closed (fixed)

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

crmn’s picture

StatusFileSize
new611 bytes

replace() only replaces the first occurance (when using strings instead of RegEx). so if there are multiple categories stored you will get something like ["essential","stats"%2C"marketing"].i created a patch with replaceAll()

flefle’s picture

Providing also the current release version 8.x-1.19 patch.

svenryen’s picture

Status: Closed (fixed) » Active
svenryen’s picture

Status: Active » Needs review

  • svenryen committed 6866d08 on 8.x-1.x authored by flefle
    Issue #3241333 by svenryen, flefle, crmn, Jeslin.Shaji, onedotover:...
svenryen’s picture

Status: Needs review » Fixed

Committed to the branch, thanks for the contribution!

Status: Fixed » Closed (fixed)

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