diff --git a/core/misc/drupal.js b/core/misc/drupal.js index d363f3adc2..f9c22198d8 100644 --- a/core/misc/drupal.js +++ b/core/misc/drupal.js @@ -642,6 +642,14 @@ window.Drupal = { behaviors: {}, locale: {} }; * @return {string} * The formatted text (html). */ + Drupal.cleanId = function (input) { + if (typeof input !== 'string') return input; + return input + .replace(/[\s_[]/g, '-') + .toLowerCase() + .replace(/[^A-Za-z0-9\-_]/g, '') + .replace(/-+/g, '-'); + }; Drupal.theme.placeholder = function (str) { return `${Drupal.checkPlain(str)}`; }; diff --git a/core/misc/form.js b/core/misc/form.js index c02220c099..b832bc6dff 100644 --- a/core/misc/form.js +++ b/core/misc/form.js @@ -286,7 +286,7 @@ } else { url = window.location; } - const hash = url.hash.substr(1); + const hash = Drupal.cleanId(url.hash.substr(1)); if (hash) { const $target = $(`#${hash}`); $('body').trigger('formFragmentLinkClickOrHashChange', [$target]);