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. && 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. 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 .