From 4ff67caa58d34c2e719913b45f512a877a1b6020 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 21 Apr 2023 03:11:46 +0000 Subject: [PATCH] Script Loader: Improve code style and readability in `_wp_normalize_relative_css_links()`. Props: westonruter. See: 58069. git-svn-id: https://develop.svn.wordpress.org/trunk@55669 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/script-loader.php | 31 ++++++++++----------- tests/phpunit/tests/dependencies/styles.php | 1 + 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 9423145a77..f48e8debeb 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2944,25 +2944,24 @@ function _wp_normalize_relative_css_links( $css, $stylesheet_url ) { static function ( $matches ) use ( $stylesheet_url ) { list( , $prefix, $url ) = $matches; - if ( ! ( - str_starts_with( $url, 'http:' ) - || - str_starts_with( $url, 'https:' ) - || - str_starts_with( $url, '//' ) - || - str_starts_with( $url, '#' ) - || + // Short-circuit if the URL does not require normalization. + if ( + str_starts_with( $url, 'http:' ) || + str_starts_with( $url, 'https:' ) || + str_starts_with( $url, '//' ) || + str_starts_with( $url, '#' ) || str_starts_with( $url, 'data:' ) - ) ) { - // Build the absolute URL. - $absolute_url = dirname( $stylesheet_url ) . '/' . $url; - $absolute_url = str_replace( '/./', '/', $absolute_url ); - - // Convert to URL related to the site root. - $url = wp_make_link_relative( $absolute_url ); + ) { + return $matches[0]; } + // Build the absolute URL. + $absolute_url = dirname( $stylesheet_url ) . '/' . $url; + $absolute_url = str_replace( '/./', '/', $absolute_url ); + + // Convert to URL related to the site root. + $url = wp_make_link_relative( $absolute_url ); + return $prefix . $url; }, $css diff --git a/tests/phpunit/tests/dependencies/styles.php b/tests/phpunit/tests/dependencies/styles.php index e0a13af5e3..ad2e672dc0 100644 --- a/tests/phpunit/tests/dependencies/styles.php +++ b/tests/phpunit/tests/dependencies/styles.php @@ -196,6 +196,7 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase { * * @ticket 54243 * @ticket 54922 + * @ticket 58069 * * @covers ::_wp_normalize_relative_css_links *