Make WordPress Core


Ignore:
Timestamp:
08/27/2025 10:32:57 AM (8 months ago)
Author:
jonsurrell
Message:

Scripts: Use appropriate JSON encoding flags for script tags.

wp_json_encode() with default arguments is insufficient to safely escape JSON for script tags. Use JSON_HEX_TAG | JSON_UNESCAPED_SLASHES flags.

Developed in https://github.com/WordPress/wordpress-develop/pull/9557.

Props devasheeshkaul, jonsurrell, siliconforks.
Fixes #63851.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-script-modules.php

    r59505 r60681  
    249249        if ( ! empty( $import_map['imports'] ) ) {
    250250            wp_print_inline_script_tag(
    251                 wp_json_encode( $import_map, JSON_HEX_TAG | JSON_HEX_AMP ),
     251                wp_json_encode( $import_map, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
    252252                array(
    253253                    'type' => 'importmap',
Note: See TracChangeset for help on using the changeset viewer.