Skip to content

Commit 90ca45a

Browse files
committed
Strip out sourceURL in script text normalization
1 parent 33d6774 commit 90ca45a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

plugins/web-worker-offloading/tests/test-web-worker-offloading.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public function test_plwwo_register_default_scripts(): void {
7171
$before_data = wp_scripts()->get_inline_script_data( 'web-worker-offloading', 'before' );
7272
$after_data = wp_scripts()->get_inline_script_data( 'web-worker-offloading', 'after' );
7373

74+
// See <https://core.trac.wordpress.org/ticket/63887>.
75+
$before_data = preg_replace( ':\n//# sourceURL=.+$:', '', $before_data );
76+
$after_data = preg_replace( ':\n//# sourceURL=.+$:', '', $after_data );
77+
7478
$this->assertTrue( wp_script_is( 'web-worker-offloading', 'registered' ) );
7579
$this->assertNotEmpty( $before_data );
7680
$this->assertNotEmpty( $after_data );
@@ -203,6 +207,15 @@ public function test_update_script_types( Closure $set_up, string $expected ): v
203207
$set_up();
204208

205209
$normalize = static function ( $html ) {
210+
// See <https://core.trac.wordpress.org/ticket/63887>.
211+
$p = new WP_HTML_Tag_Processor( $html );
212+
while ( $p->next_tag( array( 'tag_name' => 'SCRIPT' ) ) ) {
213+
$text = $p->get_modifiable_text();
214+
$text = preg_replace( ':\n//# sourceURL=.+$:', '', $text );
215+
$p->set_modifiable_text( $text );
216+
}
217+
$html = $p->get_updated_html();
218+
206219
$html = preg_replace( '/\r|\n/', '', $html );
207220
return trim( preg_replace( '#(?=<[^/])#', "\n", $html ) );
208221
};

0 commit comments

Comments
 (0)