From 2d482e076f1e3d756b534c84d8f49ecca2d55174 Mon Sep 17 00:00:00 2001 From: nod_ <nod_@598310.no-reply.drupal.org> Date: Mon, 17 Jun 2024 21:42:22 +0200 Subject: [PATCH] Issue #3238870 by shubh_, mstrelan, nod_, hooroomoo, kostyashupenko, smustgrave, larowlan, thebumik, lauriii: Refactor (if feasible) use of jquery parseHTML function to use vanillaJS (cherry picked from commit b4a02610089a67f7f34e007127e8e7ad643f5961) --- core/.eslintrc.jquery.json | 2 +- core/misc/ajax.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/.eslintrc.jquery.json b/core/.eslintrc.jquery.json index e0317d173eaf..905c8040ca78 100644 --- a/core/.eslintrc.jquery.json +++ b/core/.eslintrc.jquery.json @@ -35,7 +35,7 @@ "jquery/no-param": 2, "jquery/no-parent": 0, "jquery/no-parents": 0, - "jquery/no-parse-html": 0, + "jquery/no-parse-html": 2, "jquery/no-prop": 0, "jquery/no-proxy": 2, "jquery/no-ready": 2, diff --git a/core/misc/ajax.js b/core/misc/ajax.js index d75ece1889eb..af8fc438ca10 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -1333,7 +1333,20 @@ const settings = response.settings || ajax.settings || drupalSettings; // Parse response.data into an element collection. - let $newContent = $($.parseHTML(response.data, document, true)); + const parseHTML = (htmlString) => { + const fragment = document.createDocumentFragment(); + // Create a temporary div element + const tempDiv = fragment.appendChild(document.createElement('div')); + + // Set the innerHTML of the div to the provided HTML string + tempDiv.innerHTML = htmlString; + + // Return the contents of the temporary div + return tempDiv.childNodes; + }; + + let $newContent = $(parseHTML(response.data)); + // For backward compatibility, in some cases a wrapper will be added. This // behavior will be removed before Drupal 9.0.0. If different behavior is // needed, the theme functions can be overridden. -- GitLab