Skip to content

Commit

Permalink
Check for the validity of the src earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
anomiex authored and jeherve committed Oct 9, 2024
1 parent fc80a07 commit 20b0de6
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions projects/packages/image-cdn/src/class-image-cdn.php
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 @@ -680,8 +686,7 @@ public static function filter_the_content( $content ) {
}
}
} elseif (
is_string( $src )
&& preg_match( '#^http(s)?://i[\d]{1}.wp.com#', $src )
preg_match( '#^http(s)?://i[\d]{1}.wp.com#', $src )
&& is_string( $nearest_preceding_href )
&& self::validate_image_url( $nearest_preceding_href )
) {
Expand Down

0 comments on commit 20b0de6

Please sign in to comment.