From 7fed5bec3c3899258eb28df6dda12c3e2c0ed5b9 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Wed, 28 Sep 2022 14:57:55 +0000 Subject: [PATCH] Script Loader: Prevent double space between attributes in `WP_Styles` class. This changeset prevents `` elements to display a double space between attributes when no `title` attribute is provided. Props elten, audrasjb, whaze, SergeyBiryukov. Fixes #56675. git-svn-id: https://develop.svn.wordpress.org/trunk@54348 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-styles.php | 6 ++-- tests/phpunit/tests/dependencies/styles.php | 36 ++++++++++----------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/wp-includes/class-wp-styles.php b/src/wp-includes/class-wp-styles.php index b318d0fc17..b14ad7cbef 100644 --- a/src/wp-includes/class-wp-styles.php +++ b/src/wp-includes/class-wp-styles.php @@ -224,10 +224,10 @@ class WP_Styles extends WP_Dependencies { } $rel = isset( $obj->extra['alt'] ) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet'; - $title = isset( $obj->extra['title'] ) ? sprintf( "title='%s'", esc_attr( $obj->extra['title'] ) ) : ''; + $title = isset( $obj->extra['title'] ) ? sprintf( " title='%s'", esc_attr( $obj->extra['title'] ) ) : ''; $tag = sprintf( - "\n", + "\n", $rel, $handle, $title, @@ -259,7 +259,7 @@ class WP_Styles extends WP_Dependencies { } $rtl_tag = sprintf( - "\n", + "\n", $rel, $handle, $title, diff --git a/tests/phpunit/tests/dependencies/styles.php b/tests/phpunit/tests/dependencies/styles.php index 8e7721d1e9..34a9847f2f 100644 --- a/tests/phpunit/tests/dependencies/styles.php +++ b/tests/phpunit/tests/dependencies/styles.php @@ -63,10 +63,10 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase { wp_enqueue_style( 'no-deps-null-version-print-media', 'example.com', array(), null, 'print' ); $ver = get_bloginfo( 'version' ); - $expected = "\n"; - $expected .= "\n"; - $expected .= "\n"; - $expected .= "\n"; + $expected = "\n"; + $expected .= "\n"; + $expected .= "\n"; + $expected .= "\n"; $this->assertSame( $expected, get_echo( 'wp_print_styles' ) ); @@ -86,7 +86,7 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase { wp_enqueue_style( 'no-deps-no-version', 'example.com' ); $ver = get_bloginfo( 'version' ); - $expected = "\n"; + $expected = "\n"; $this->assertSame( $expected, get_echo( 'wp_print_styles' ) ); } @@ -107,24 +107,24 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase { // Try with an HTTP reference. wp_enqueue_style( 'reset-css-http', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' ); - $expected .= "\n"; + $expected .= "\n"; // Try with an HTTPS reference. wp_enqueue_style( 'reset-css-https', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' ); - $expected .= "\n"; + $expected .= "\n"; // Try with an automatic protocol reference (//). wp_enqueue_style( 'reset-css-doubleslash', '//yui.yahooapis.com/2.8.1/build/reset/reset-min.css' ); - $expected .= "\n"; + $expected .= "\n"; // Try with a local resource and an automatic protocol reference (//). $url = '//my_plugin/style.css'; wp_enqueue_style( 'plugin-style', $url ); - $expected .= "\n"; + $expected .= "\n"; // Try with a bad protocol. wp_enqueue_style( 'reset-css-ftp', 'ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' ); - $expected .= "\n"; + $expected .= "\n"; // Go! $this->assertSame( $expected, get_echo( 'wp_print_styles' ) ); @@ -147,7 +147,7 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase { $style .= "\tbackground: red;\n"; $style .= '}'; - $expected = "\n"; + $expected = "\n"; $expected .= "\n"; @@ -176,7 +176,7 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase { $style .= "\tbackground: red;\n"; $style .= '}'; - $expected = "\n"; + $expected = "\n"; $expected .= "\n"; @@ -258,7 +258,7 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase { $style2 .= "\tbackground: blue;\n"; $style2 .= '}'; - $expected = "\n"; + $expected = "\n"; $expected .= "'; - $expected = "\n"; + $expected = "\n"; $expected .= "$style\n"; wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); @@ -305,7 +305,7 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase { */ public function test_unnecessary_style_tags() { - $expected = "\n"; + $expected = "\n"; wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); @@ -320,7 +320,7 @@ class Tests_Dependencies_Styles extends WP_UnitTestCase { public function test_conditional_inline_styles_are_also_conditional() { $expected = << - + @@ -350,8 +350,8 @@ CSS; public function test_wp_add_inline_style_for_handle_without_source() { $style = 'a { color: blue; }'; - $expected = "\n"; - $expected .= "\n"; + $expected = "\n"; + $expected .= "\n"; $expected .= "\n";