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.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | unexpected-token-replace-8-1.19-3241333-1.patch | 610 bytes | flefle |
| #17 | unexpected-token-replace-3241333.patch | 611 bytes | crmn |
| #4 | newcookie-1.16.png | 40.97 KB | jeslin.shaji |
| #4 | oldcookie-1.14.png | 45.11 KB | jeslin.shaji |
Issue fork eu_cookie_compliance-3241333
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
Comment #2
ivnishIs it actual for 1.18 ?
Comment #3
svenryen commented@Jeslin.Shaji, what's your cookie value? and are the machine names of your categories?
Comment #4
jeslin.shaji commented@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.
Comment #5
svenryen commentedThanks, will be taking a look this weekend. The change in formatting was not intentional.
Comment #6
svenryen commentedThis 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.
Comment #8
svenryen commentedA fix is in the issue branch.
For those who want a patch file: https://git.drupalcode.org/project/eu-cookie-compliance/-/merge_requests...
Comment #10
svenryen commentedComment #11
onedotover commentedHi 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:
Comment #12
svenryen commentedThanks, @onedotover, I'll take a look.
Comment #13
svenryen commentedComment #15
svenryen commentedReviewed and tested. Thanks for contributing! :)
Comment #17
crmn commentedreplace() 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()Comment #18
flefle commentedProviding also the current release version 8.x-1.19 patch.
Comment #19
svenryen commentedComment #20
svenryen commentedComment #22
svenryen commentedCommitted to the branch, thanks for the contribution!