Skip to content

Commit

Permalink
Script Loader: Do not normalize absolute paths in inline block styles…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
SergeyBiryukov committed Aug 25, 2024
1 parent 0687800 commit 4905653
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3056,7 +3056,7 @@ static function ( $matches ) use ( $stylesheet_url ) {
if (
str_starts_with( $url, 'http:' ) ||
str_starts_with( $url, 'https:' ) ||
str_starts_with( $url, '//' ) ||
str_starts_with( $url, '/' ) ||
str_starts_with( $url, '#' ) ||
str_starts_with( $url, 'data:' )
) {
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/tests/dependencies/styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ public function data_normalize_relative_css_links() {
'css' => 'p {background-image: url(\'../image1.jpg\');}',
'expected' => 'p {background-image: url(\'/wp-content/themes/test/../image1.jpg\');}',
),
'URLs with absolute path, shouldn\'t change' => array(
'css' => 'p {background:url( "/image0.svg" );}',
'expected' => 'p {background:url( "/image0.svg" );}',
),
'External URLs, shouldn\'t change' => array(
'css' => 'p {background-image: url(\'http://foo.com/image2.png\');}',
'expected' => 'p {background-image: url(\'http://foo.com/image2.png\');}',
Expand Down

0 comments on commit 4905653

Please sign in to comment.