Uncaught SyntaxError: Bad escaped character in JSON

Created on 30 April 2025, 3 months ago

Problem/Motivation

When putting an escape character in "Include links matching the pattern.": like with (.\.pdf|\/download)$.

It works as an authenticated user because in extlink/js/extlink.js, the following code is executed:

    if (drupalSettings.data.extlink.extInclude) {
      extInclude = new RegExp(drupalSettings.data.extlink.extInclude.replace(/\\/, '\\'), 'i');
    }

But for anonymous users, they end up into this return:

  Drupal.extlink.attach = (context, drupalSettings) => {
    if (typeof drupalSettings.data === 'undefined' || !drupalSettings.data.hasOwnProperty('extlink')) {
      return;
    }

So this is not properly replaced and provokes this error:

Uncaught SyntaxError: Bad escaped character in JSON at position 1410 (line 1 column 1411)

Steps to reproduce

In "Include links matching the pattern.", put: (.\.pdf|\/download)$

Go on the website as an anonymous user.

Proposed resolution

Checking why it is not directly in a Drupal behavior.

Remaining tasks

Find root cause and propose fix.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France Grimreaper France 🇫🇷

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024