Make WordPress Core


Ignore:
Timestamp:
11/18/2025 10:10:49 AM (5 months ago)
Author:
jonsurrell
Message:

Script Loader: Omit sourceURL from translation data when not printed.

The data returned from WP_Scripts::print_translations() when $display is false may be used in unpredictable ways that are incompatible with sourceURL comments. Omit the sourceURL comment in this case.

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

Follow-up to [60719].

Reviewed by westonruter.
Merges [61223] to the 6.9 branch.

Props jonsurrell, ralucastn, westonruter, peterwilsoncc.
See #63887.

Location:
branches/6.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.9

  • branches/6.9/tests/phpunit/tests/dependencies/scripts.php

    r61176 r61260  
    40764076        $this->assertEqualHTML( $expected, $print_scripts );
    40774077    }
     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    }
    40784096}
Note: See TracChangeset for help on using the changeset viewer.