- Timestamp:
- 05/15/2024 05:40:44 PM (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api.php
r58127 r58159 168 168 169 169 if ( ! empty( $interactivity_data ) ) { 170 /* 171 * This data will be printed as JSON inside a script tag like this: 172 * <script type="application/json"></script> 173 * 174 * A script tag must be closed by a sequence beginning with `</`. It's impossible to 175 * close a script tag without using `<`. We ensure that `<` is escaped and `/` can 176 * remain unescaped, so `</script>` will be printed as `\u003C/script\u00E3`. 177 * 178 * - JSON_HEX_TAG: All < and > are converted to \u003C and \u003E. 179 * - JSON_UNESCAPED_SLASHES: Don't escape /. 180 * 181 * If the page will use UTF-8 encoding, it's safe to print unescaped unicode: 182 * 183 * - JSON_UNESCAPED_UNICODE: Encode multibyte Unicode characters literally (instead of as `\uXXXX`). 184 * - JSON_UNESCAPED_LINE_TERMINATORS: The line terminators are kept unescaped when 185 * JSON_UNESCAPED_UNICODE is supplied. It uses the same behaviour as it was 186 * before PHP 7.1 without this constant. Available as of PHP 7.1.0. 187 * 188 * The JSON specification requires encoding in UTF-8, so if the generated HTML page 189 * is not encoded in UTF-8 then it's not safe to include those literals. They must 190 * be escaped to avoid encoding issues. 191 * 192 * @see https://www.rfc-editor.org/rfc/rfc8259.html for details on encoding requirements. 193 * @see https://www.php.net/manual/en/json.constants.php for details on these constants. 194 * @see https://html.spec.whatwg.org/#script-data-state for details on script tag parsing. 195 */ 196 $json_encode_flags = JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_LINE_TERMINATORS; 197 if ( ! is_utf8_charset() ) { 198 $json_encode_flags = JSON_HEX_TAG | JSON_UNESCAPED_SLASHES; 199 } 200 170 201 wp_print_inline_script_tag( 171 202 wp_json_encode( 172 203 $interactivity_data, 173 JSON_HEX_TAG | JSON_HEX_AMP204 $json_encode_flags 174 205 ), 175 206 array(
Note: See TracChangeset
for help on using the changeset viewer.