Changeset 61260
- Timestamp:
- 11/18/2025 10:10:49 AM (3 months ago)
- Location:
- branches/6.9
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
src/wp-includes/class-wp-scripts.php (modified) (3 diffs)
-
tests/phpunit/tests/dependencies/scripts.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/6.9
-
branches/6.9/src/wp-includes/class-wp-scripts.php
r61176 r61260 351 351 $translations = $this->print_translations( $handle, false ); 352 352 if ( $translations ) { 353 $translations = wp_get_inline_script_tag( $translations, array( 'id' => "{$handle}-js-translations" ) ); 353 /* 354 * The sourceURL comment is not included by WP_Scripts::print_translations() 355 * when `$display` is `false` to prevent issues where the script tag contents are used 356 * by extenders for other purposes, for example concatenated with other script content. 357 * 358 * Include the sourceURL comment here as it would be when printed directly. 359 */ 360 $source_url = rawurlencode( "{$handle}-js-translations" ); 361 $translations .= "\n//# sourceURL={$source_url}"; 362 $translations = wp_get_inline_script_tag( $translations, array( 'id' => "{$handle}-js-translations" ) ); 354 363 } 355 364 … … 723 732 } 724 733 725 $source_url = rawurlencode( "{$handle}-js-translations" );726 727 734 $output = <<<JS 728 735 ( function( domain, translations ) { … … 731 738 wp.i18n.setLocaleData( localeData, domain ); 732 739 } )( "{$domain}", {$json_translations} ); 733 //# sourceURL={$source_url}734 740 JS; 735 741 736 742 if ( $display ) { 743 $source_url = rawurlencode( "{$handle}-js-translations" ); 744 $output .= "\n//# sourceURL={$source_url}"; 737 745 wp_print_inline_script_tag( $output, array( 'id' => "{$handle}-js-translations" ) ); 738 746 } -
branches/6.9/tests/phpunit/tests/dependencies/scripts.php
r61176 r61260 4076 4076 $this->assertEqualHTML( $expected, $print_scripts ); 4077 4077 } 4078 4079 /** 4080 * Ensure that `::print_translations()` does not include the sourceURL comment when `$display` is false. 4081 * 4082 * @ticket 63887 4083 * @covers ::print_translations 4084 */ 4085 public function test_print_translations_no_display_no_sourceurl() { 4086 global $wp_scripts; 4087 $this->add_html5_script_theme_support(); 4088 4089 wp_register_script( 'wp-i18n', '/wp-includes/js/dist/wp-i18n.js', array(), null ); 4090 wp_enqueue_script( 'test-example', '/wp-includes/js/script.js', array(), null ); 4091 wp_set_script_translations( 'test-example', 'default', DIR_TESTDATA . '/languages' ); 4092 4093 $translations_script_data = $wp_scripts->print_translations( 'test-example', false ); 4094 $this->assertStringNotContainsStringIgnoringCase( 'sourceURL=', $translations_script_data ); 4095 } 4078 4096 }
Note: See TracChangeset
for help on using the changeset viewer.