Skip to content

Commit 4905653

Browse files
Script Loader: Do not normalize absolute paths in inline block styles CSS.
`_wp_normalize_relative_css_links()` used to normalize all non-absolute URLs regardless of whether it's a relative path or an absolute path. The normalization should only happen for relative paths (paths without a leading `/`) and not for absolute paths. Reference: [https://www.rfc-editor.org/rfc/rfc1808#section-4 RFC 1808, Section 4, Step 4]. Follow-up to [52036], [52695], [52754], [55658], [55669]. Props scholdstrom. Fixes #61909. git-svn-id: https://develop.svn.wordpress.org/trunk@58932 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 0687800 commit 4905653

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/wp-includes/script-loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3056,7 +3056,7 @@ static function ( $matches ) use ( $stylesheet_url ) {
30563056
if (
30573057
str_starts_with( $url, 'http:' ) ||
30583058
str_starts_with( $url, 'https:' ) ||
3059-
str_starts_with( $url, '//' ) ||
3059+
str_starts_with( $url, '/' ) ||
30603060
str_starts_with( $url, '#' ) ||
30613061
str_starts_with( $url, 'data:' )
30623062
) {

tests/phpunit/tests/dependencies/styles.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ public function data_normalize_relative_css_links() {
228228
'css' => 'p {background-image: url(\'../image1.jpg\');}',
229229
'expected' => 'p {background-image: url(\'/wp-content/themes/test/../image1.jpg\');}',
230230
),
231+
'URLs with absolute path, shouldn\'t change' => array(
232+
'css' => 'p {background:url( "/image0.svg" );}',
233+
'expected' => 'p {background:url( "/image0.svg" );}',
234+
),
231235
'External URLs, shouldn\'t change' => array(
232236
'css' => 'p {background-image: url(\'http://foo.com/image2.png\');}',
233237
'expected' => 'p {background-image: url(\'http://foo.com/image2.png\');}',

0 commit comments

Comments
 (0)