Skip to content

Commit

Permalink
Photon: avoid deprecation warnings when src is null (#39685)
Browse files Browse the repository at this point in the history
* Photon: avoid deprecation warnings when src is null

In some scenarios, one can run into the following deprecation notices:

Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /wordpress/plugins/jetpack/13.9-a.7/jetpack_vendor/automattic/jetpack-image-cdn/src/class-image-cdn.php on line 682

This should avoid those notices.

* Check for the validity of the src earlier

See Automattic/jetpack#39685 (review)

---------

Co-authored-by: Brad Jorsch <[email protected]>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/11273239508

Upstream-Ref: Automattic/jetpack@1566a4e
  • Loading branch information
dilirity authored and matticbot committed Oct 10, 2024
1 parent 77c825e commit 14d6e92
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 110 deletions.
1 change: 1 addition & 0 deletions jetpack_vendor/automattic/jetpack-image-cdn/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
This is an alpha version! The changes listed here are not final.

### Fixed
- Avoid deprecation notice when an image URL does not have an expected format.
- URL encode path parts of an image

## [0.5.0] - 2024-10-07
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,21 @@ public static function filter_the_content( $content ) {
continue;
}

// Identify image source.
$src_orig = $processor->get_attribute( 'src' );
$src = $src_orig;

/*
* Only examine tags that are considered an image. If encountering
* a closing tag then this is not the image being sought.
* Only examine tags that are considered an image,
* with a valid src attribute.
* If encountering a closing tag then this is not the image being sought.
*/
if ( $processor->is_tag_closer() || ! in_array( $processor->get_tag(), $image_tags, true ) ) {
if (
$processor->is_tag_closer()
|| ! in_array( $processor->get_tag(), $image_tags, true )
|| ! is_string( $src )
|| $src === ''
) {
continue;
}

Expand Down Expand Up @@ -397,10 +407,6 @@ public static function filter_the_content( $content ) {
// Flag if we need to munge a fullsize URL.
$fullsize_url = false;

// Identify image source.
$src_orig = $processor->get_attribute( 'src' );
$src = $src_orig;

/**
* Allow specific images to be skipped by Photon.
*
Expand Down Expand Up @@ -679,7 +685,11 @@ public static function filter_the_content( $content ) {
$processor->set_attribute( 'data-recalc-dims', '1' );
}
}
} elseif ( preg_match( '#^http(s)?://i[\d]{1}.wp.com#', $src ) && is_string( $nearest_preceding_href ) && self::validate_image_url( $nearest_preceding_href ) ) {
} elseif (
preg_match( '#^http(s)?://i[\d]{1}.wp.com#', $src )
&& is_string( $nearest_preceding_href )
&& self::validate_image_url( $nearest_preceding_href )
) {
$processor->seek( 'link' );
$processor->set_attribute( 'href', Image_CDN_Core::cdn_url( $nearest_preceding_href ) );
$processor->seek( 'image' );
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/i18n-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
),
'jetpack-image-cdn' => array(
'path' => 'jetpack_vendor/automattic/jetpack-image-cdn',
'ver' => '0.5.1-alpha1728387153',
'ver' => '0.5.1-alpha1728560225',
),
'jetpack-import' => array(
'path' => 'jetpack_vendor/automattic/jetpack-import',
Expand Down
Loading

0 comments on commit 14d6e92

Please sign in to comment.