Skip to content

Fix background-image styled tag visitor's handling of parsing style without background-image #1288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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*(?<background_image>.+?)\s*[\'"]?\s*\)/', $style, $matches )
0 < (int) preg_match( '/background(-image)?\s*:[^;]*?url\(\s*[\'"]?\s*(?<background_image>.+?)\s*[\'"]?\s*\)/', $style, $matches )
&&
'' !== $matches['background_image'] // PHPStan should ideally know that this is a non-empty string based on the `.+?` regular expression.
&&
Expand Down
4 changes: 2 additions & 2 deletions plugins/image-prioritizer/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion plugins/image-prioritizer/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
28 changes: 28 additions & 0 deletions plugins/image-prioritizer/tests/test-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '
<html lang="en">
<head>
<meta charset="utf-8">
<title>...</title>
</head>
<body>
<div style="background-color: black; color: white; width:100%; height: 200px;">This is so background!</div>
</body>
</html>
',
// There should be no data-od-xpath added to the DIV because it is using a data: URL for the background-image.
'expected' => '
<html lang="en">
<head>
<meta charset="utf-8">
<title>...</title>
</head>
<body>
<div style="background-color: black; color: white; width:100%; height: 200px;">This is so background!</div>
<script type="module">/* import detect ... */</script>
</body>
</html>
',
),

'no-url-metrics-with-data-url-image' => array(
'set_up' => static function (): void {},
// Smallest PNG courtesy of <https://evanhahn.com/worlds-smallest-png/>.
Expand Down
Loading