Changeset 61415 for trunk/src/wp-includes/script-loader.php
- Timestamp:
- 12/29/2025 11:32:17 AM (3 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/script-loader.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/script-loader.php
r61414 r61415 2211 2211 if ( ! empty( $wp_scripts->print_code ) ) { 2212 2212 echo "\n<script>\n"; 2213 echo "/* <![CDATA[ */\n"; // Not needed in HTML 5.2214 2213 echo $wp_scripts->print_code; 2215 2214 echo sprintf( "\n//# sourceURL=%s\n", rawurlencode( 'js-inline-concat-' . $concat ) ); 2216 echo "/* ]]> */\n";2217 2215 echo "</script>\n"; 2218 2216 } … … 2872 2870 */ 2873 2871 function wp_sanitize_script_attributes( $attributes ) { 2874 $html5_script_support = is_admin() || current_theme_supports( 'html5', 'script' ); 2875 $attributes_string = ''; 2872 $attributes_string = ''; 2876 2873 2877 2874 /* … … 2882 2879 if ( is_bool( $attribute_value ) ) { 2883 2880 if ( $attribute_value ) { 2884 $attributes_string .= $html5_script_support ? ' ' . esc_attr( $attribute_name ) : sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_name ));2881 $attributes_string .= ' ' . esc_attr( $attribute_name ); 2885 2882 } 2886 2883 } else { … … 2945 2942 */ 2946 2943 function wp_get_inline_script_tag( $data, $attributes = array() ) { 2947 /*2948 * XHTML extracts the contents of the SCRIPT element and then the XML parser2949 * decodes character references and other syntax elements. This can lead to2950 * misinterpretation of the script contents or invalid XHTML documents.2951 *2952 * Wrapping the contents in a CDATA section instructs the XML parser not to2953 * transform the contents of the SCRIPT element before passing them to the2954 * JavaScript engine.2955 *2956 * Example:2957 *2958 * <script>console.log('…');</script>2959 *2960 * In an HTML document this would print "…" to the console,2961 * but in an XHTML document it would print "…" to the console.2962 *2963 * <script>console.log('An image is <img> in HTML');</script>2964 *2965 * In an HTML document this would print "An image is <img> in HTML",2966 * but it's an invalid XHTML document because it interprets the `<img>`2967 * as an empty tag missing its closing `/`.2968 *2969 * @see https://www.w3.org/TR/xhtml1/#h-4.82970 */2971 if (2972 ( ! current_theme_supports( 'html5', 'script' ) && ! is_admin() )2973 && (2974 ! isset( $attributes['type'] ) ||2975 'module' === $attributes['type'] ||2976 str_contains( $attributes['type'], 'javascript' ) ||2977 str_contains( $attributes['type'], 'ecmascript' ) ||2978 str_contains( $attributes['type'], 'jscript' ) ||2979 str_contains( $attributes['type'], 'livescript' )2980 )2981 ) {2982 /*2983 * If the string `]]>` exists within the JavaScript it would break2984 * out of any wrapping CDATA section added here, so to start, it's2985 * necessary to escape that sequence which requires splitting the2986 * content into two CDATA sections wherever it's found.2987 *2988 * Note: it's only necessary to escape the closing `]]>` because2989 * an additional `<![CDATA[` leaves the contents unchanged.2990 */2991 $data = str_replace( ']]>', ']]]]><![CDATA[>', $data );2992 2993 // Wrap the entire escaped script inside a CDATA section.2994 $data = sprintf( "/* <![CDATA[ */\n%s\n/* ]]> */", $data );2995 }2996 2997 2944 $data = "\n" . trim( $data, "\n\r " ) . "\n"; 2998 2945
Note: See TracChangeset
for help on using the changeset viewer.