From 38b62cdb14ec5423c31d761c9885d533b17ae01c Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 7 Jun 2024 11:12:14 -0700 Subject: [PATCH 1/3] Add failing test case for a non-background image style --- .../image-prioritizer/tests/test-helper.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/plugins/image-prioritizer/tests/test-helper.php b/plugins/image-prioritizer/tests/test-helper.php index 8e9e345d5c..12a3207fc3 100644 --- a/plugins/image-prioritizer/tests/test-helper.php +++ b/plugins/image-prioritizer/tests/test-helper.php @@ -86,6 +86,34 @@ public function data_provider_test_filter_tag_walker_visitors(): array { ', ), + 'no-url-metrics-with-non-background-image-style' => array( + 'set_up' => static function (): void {}, + 'buffer' => ' + + + + Codestin Search App + + +
This is so background!
+ + + ', + // There should be no data-od-xpath added to the DIV because it is using a data: URL for the background-image. + 'expected' => ' + + + + Codestin Search App + + +
This is so background!
+ + + + ', + ), + 'no-url-metrics-with-data-url-image' => array( 'set_up' => static function (): void {}, // Smallest PNG courtesy of . From e9d997c97a6b06b73669844ef31ad520cd5e90ff Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 7 Jun 2024 11:18:40 -0700 Subject: [PATCH 2/3] Fix logic error for preg_match() return value --- ...ss-image-prioritizer-background-image-styled-tag-visitor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/image-prioritizer/class-image-prioritizer-background-image-styled-tag-visitor.php b/plugins/image-prioritizer/class-image-prioritizer-background-image-styled-tag-visitor.php index 7969d26f3b..8d1f7a6d68 100644 --- a/plugins/image-prioritizer/class-image-prioritizer-background-image-styled-tag-visitor.php +++ b/plugins/image-prioritizer/class-image-prioritizer-background-image-styled-tag-visitor.php @@ -39,7 +39,7 @@ public function __invoke( OD_HTML_Tag_Walker $walker ): bool { if ( is_string( $style ) && - false !== preg_match( '/background(-image)?\s*:[^;]*?url\(\s*[\'"]?\s*(?.+?)\s*[\'"]?\s*\)/', $style, $matches ) + 0 < (int) preg_match( '/background(-image)?\s*:[^;]*?url\(\s*[\'"]?\s*(?.+?)\s*[\'"]?\s*\)/', $style, $matches ) && '' !== $matches['background_image'] // PHPStan should ideally know that this is a non-empty string based on the `.+?` regular expression. && From 8fa37b08cc8c5cdba4b4c6a2508df1442576c351 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 7 Jun 2024 11:21:04 -0700 Subject: [PATCH 3/3] Bump version to 0.1.1 --- plugins/image-prioritizer/load.php | 4 ++-- plugins/image-prioritizer/readme.txt | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/image-prioritizer/load.php b/plugins/image-prioritizer/load.php index aa5606fdf6..7f632c69c3 100644 --- a/plugins/image-prioritizer/load.php +++ b/plugins/image-prioritizer/load.php @@ -6,7 +6,7 @@ * Requires at least: 6.4 * Requires PHP: 7.2 * Requires Plugins: optimization-detective - * Version: 0.1.0 + * Version: 0.1.1 * Author: WordPress Performance Team * Author URI: https://make.wordpress.org/performance/ * License: GPLv2 or later @@ -66,7 +66,7 @@ static function ( string $global_var_name, string $version, Closure $load ): voi } )( 'image_prioritizer_pending_plugin', - '0.1.0', + '0.1.1', static function ( string $version ): void { // Define the constant. diff --git a/plugins/image-prioritizer/readme.txt b/plugins/image-prioritizer/readme.txt index 5da697287e..8a3be715a8 100644 --- a/plugins/image-prioritizer/readme.txt +++ b/plugins/image-prioritizer/readme.txt @@ -4,7 +4,7 @@ Contributors: wordpressdotorg Requires at least: 6.4 Tested up to: 6.5 Requires PHP: 7.2 -Stable tag: 0.1.0 +Stable tag: 0.1.1 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: performance, optimization, image, lcp, lazy-load @@ -64,6 +64,10 @@ The [plugin source code](https://github.com/WordPress/performance/tree/trunk/plu == Changelog == += 0.1.1 = + +* Fix background-image styled tag visitor's handling of parsing style without background-image. ([1288](https://github.com/WordPress/performance/pull/1288)) + = 0.1.0 = * Initial release.