From 0ccaae350bbbfa0fcd01c368660e9998ab2d5d5a Mon Sep 17 00:00:00 2001
From: Matthijs Van Assche <26224-Matthijs@users.noreply.drupalcode.org>
Date: Mon, 24 Feb 2025 15:01:35 +0000
Subject: [PATCH 1/2] Issue #3508677: Fix support for special characters in
 active-link.js

---
 core/misc/active-link.js | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/core/misc/active-link.js b/core/misc/active-link.js
index 464e9a4044f0..f31fa6f9cc92 100644
--- a/core/misc/active-link.js
+++ b/core/misc/active-link.js
@@ -20,15 +20,40 @@
    */
   Drupal.behaviors.activeLinks = {
     attach(context) {
+      // JSON encode an object.
+      const jsonEncode = (object, stringify) => {
+        object = structuredClone(object);
+        const entries = Object.entries(object);
+
+        for (let i = 0; i < entries.length; i += 1) {
+          const [key, value] = entries[i];
+
+          if (typeof value === 'string') {
+            object[key] = value
+              .replace(/[\u007F-\uFFFF\u003c\u003e\u0022\u0027\u0026]/g, (chr) => {
+                return '&u' + ('0000' + chr.charCodeAt(0).toString(16)).substr(-4);
+              });
+          }
+          else if (typeof value === 'object') {
+            object[key] = jsonEncode(value, false);
+          }
+        }
+
+        if (stringify === false) {
+          return object;
+        }
+
+        return JSON.stringify(object).replace('&u', '\\u');
+      };
+
       // Start by finding all potentially active links.
       const path = drupalSettings.path;
-      const queryString = JSON.stringify(path.currentQuery);
-      const querySelector = queryString
-        ? `[data-drupal-link-query="${CSS.escape(queryString)}"]`
-        : ':not([data-drupal-link-query])';
       const originalSelectors = [
         `[data-drupal-link-system-path="${CSS.escape(path.currentPath)}"]`,
       ];
+      const querySelector = path.currentQuery
+        ? `[data-drupal-link-query="${CSS.escape(jsonEncode(path.currentQuery))}"]`
+        : ':not([data-drupal-link-query])';
       let selectors;
 
       // If this is the front page, we have to check for the <front> path as
-- 
GitLab


From 2e27901fb9171132dbd9d13c562d6fd8ed1c85fe Mon Sep 17 00:00:00 2001
From: Matthijs Van Assche <26224-Matthijs@users.noreply.drupalcode.org>
Date: Mon, 24 Feb 2025 15:13:10 +0000
Subject: [PATCH 2/2] Issue #3508677: Update code styling

---
 core/misc/active-link.js | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/core/misc/active-link.js b/core/misc/active-link.js
index f31fa6f9cc92..acc8bf8daaab 100644
--- a/core/misc/active-link.js
+++ b/core/misc/active-link.js
@@ -29,10 +29,12 @@
           const [key, value] = entries[i];
 
           if (typeof value === 'string') {
-            object[key] = value
-              .replace(/[\u007F-\uFFFF\u003c\u003e\u0022\u0027\u0026]/g, (chr) => {
+            object[key] = value.replace(
+              /[\u007F-\uFFFF\u003c\u003e\u0022\u0027\u0026]/g,
+              (chr) => {
                 return '&u' + ('0000' + chr.charCodeAt(0).toString(16)).substr(-4);
-              });
+              }
+            );
           }
           else if (typeof value === 'object') {
             object[key] = jsonEncode(value, false);
-- 
GitLab