Changeset 57341
- Timestamp:
- 01/23/2024 05:54:25 PM (11 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/script-loader.php
r57312 r57341 2880 2880 * @see https://www.w3.org/TR/xhtml1/#h-4.8 2881 2881 */ 2882 if ( ! $is_html5 ) { 2882 if ( 2883 ! $is_html5 && 2884 ( 2885 ! isset( $attributes['type'] ) || 2886 'module' === $attributes['type'] || 2887 str_contains( $attributes['type'], 'javascript' ) || 2888 str_contains( $attributes['type'], 'ecmascript' ) || 2889 str_contains( $attributes['type'], 'jscript' ) || 2890 str_contains( $attributes['type'], 'livescript' ) 2891 ) 2892 ) { 2883 2893 /* 2884 2894 * If the string `]]>` exists within the JavaScript it would break -
trunk/tests/phpunit/tests/dependencies/wpInlineScriptTag.php
r56687 r57341 11 11 class Tests_Functions_wpInlineScriptTag extends WP_UnitTestCase { 12 12 13 private $original_theme_features = array(); 14 15 public function set_up() { 16 global $_wp_theme_features; 17 parent::set_up(); 18 $this->original_theme_features = $_wp_theme_features; 19 } 20 21 public function tear_down() { 22 global $_wp_theme_features; 23 $_wp_theme_features = $this->original_theme_features; 24 parent::tear_down(); 25 } 26 13 27 private $event_handler = <<<'JS' 14 28 document.addEventListener( 'DOMContentLoaded', function () { … … 134 148 ); 135 149 } 150 151 public function data_provider_to_test_cdata_wrapper_omitted_for_non_javascript_scripts() { 152 return array( 153 'no-type' => array( 154 'type' => null, 155 'data' => 'alert("hello")', 156 'expected_cdata' => true, 157 ), 158 'js-type' => array( 159 'type' => 'text/javascript', 160 'data' => 'alert("hello")', 161 'expected_cdata' => true, 162 ), 163 'js-alt-type' => array( 164 'type' => 'application/javascript', 165 'data' => 'alert("hello")', 166 'expected_cdata' => true, 167 ), 168 'module' => array( 169 'type' => 'module', 170 'data' => 'alert("hello")', 171 'expected_cdata' => true, 172 ), 173 'importmap' => array( 174 'type' => 'importmap', 175 'data' => '{"imports":{"bar":"http:\/\/localhost:10023\/bar.js?ver=6.5-alpha-57321"}}', 176 'expected_cdata' => false, 177 ), 178 'html' => array( 179 'type' => 'text/html', 180 'data' => '<div>template code</div>', 181 'expected_cdata' => false, 182 ), 183 'json' => array( 184 'type' => 'application/json', 185 'data' => '{}', 186 'expected_cdata' => false, 187 ), 188 'ld' => array( 189 'type' => 'application/ld+json', 190 'data' => '{}', 191 'expected_cdata' => false, 192 ), 193 'specrules' => array( 194 'type' => 'speculationrules', 195 'data' => '{}', 196 'expected_cdata' => false, 197 ), 198 ); 199 } 200 201 /** 202 * Tests that CDATA wrapper is not added for non-JavaScript scripts. 203 * 204 * @ticket 60320 205 * 206 * @dataProvider data_provider_to_test_cdata_wrapper_omitted_for_non_javascript_scripts 207 */ 208 public function test_cdata_wrapper_omitted_for_non_javascript_scripts( $type, $data, $expected_cdata ) { 209 remove_theme_support( 'html5' ); 210 211 $attrs = array(); 212 if ( $type ) { 213 $attrs['type'] = $type; 214 } 215 $script = wp_get_inline_script_tag( $data, $attrs ); 216 $this->assertSame( $expected_cdata, str_contains( $script, '/* <![CDATA[ */' ) ); 217 $this->assertSame( $expected_cdata, str_contains( $script, '/* ]]> */' ) ); 218 $this->assertStringContainsString( $data, $script ); 219 } 136 220 }
Note: See TracChangeset
for help on using the changeset viewer.