Make WordPress Core

Changeset 63059


Ignore:
Timestamp:
08/06/2026 03:29:43 PM (6 weeks ago)
Author:
johnbillion
Message:

Emoji: Ensure that the emoji settings come from a script element.

Props westonruter, jonsurrell, peterwilsoncc, davidbinda, lucasbustamante.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/emoji-loader.js

    r61134 r63059  
    1717 */
    1818
    19 const settings = /** @type {WPEmojiSettings} */ (
    20         JSON.parse( document.getElementById( 'wp-emoji-settings' ).textContent )
    21 );
     19const selector = 'script#wp-emoji-settings';
     20const script = document.querySelector( selector );
     21if ( ! ( script instanceof HTMLScriptElement ) ) {
     22        throw new Error( `Element missing: ${ selector }`);
     23}
     24const settings = /** @type {WPEmojiSettings} */ ( JSON.parse( script.text ) );
    2225
    2326// For compatibility with other scripts that read from this global, in particular wp-includes/js/wp-emoji.js (source file: js/_enqueues/wp/emoji.js).
  • trunk/src/wp-includes/class-wp-script-modules.php

    r62278 r63059  
    10591059                         * tag with an ID of the form `wp-script-module-data-{$module_id}`.
    10601060                         *
    1061                          * The data can be read on the client with a pattern like this:
     1061                         * The data can be read on the client with a pattern like the following; you are encouraged
     1062                         * to use this pattern _verbatim_ to avoid common pitfalls or vulnerabilities:
    10621063                         *
    10631064                         * Example:
    10641065                         *
    1065                          *     const dataContainer = document.getElementById( 'wp-script-module-data-MyScriptModuleID' );
     1066                         *     const dataContainer = document.querySelector( 'script[id="wp-script-module-data-MyScriptModuleID"]' );
    10661067                         *     let data = {};
    1067                          *     if ( dataContainer ) {
     1068                         *     if ( dataContainer instanceof HTMLScriptElement ) {
    10681069                         *         try {
    1069                          *             data = JSON.parse( dataContainer.textContent );
     1070                         *             data = JSON.parse( dataContainer.text );
    10701071                         *         } catch {}
    10711072                         *     }
Note: See TracChangeset for help on using the changeset viewer.