Skip to content

Commit

Permalink
extra checks in can_optimize_image to take weird image URL's into acc…
Browse files Browse the repository at this point in the history
…ount (e.g. <img src="#">)
  • Loading branch information
futtta committed Feb 3, 2024
1 parent 81f1069 commit 2fa3c9e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions classes/autoptimizeImages.php
Expand Up @@ -513,15 +513,17 @@ private function can_optimize_image( $url, $tag = '', $testing = false )
$url = $this->normalize_img_url( $url );
$url_parsed = parse_url( $url );

if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
if ( false === is_array( $url_parsed ) ) {
return false;
} elseif ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
return false;
} elseif ( autoptimizeUtils::is_local_server() ) {
return false;
} elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) {
return false;
} elseif ( strpos( $url, '.php' ) !== false ) {
return false;
} elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) {
} elseif ( false === array_key_exists( 'path', $url_parsed ) || str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) {
// fixme: better check against end of string.
return false;
} elseif ( ! empty( $nopti_images ) ) {
Expand Down

0 comments on commit 2fa3c9e

Please sign in to comment.