Skip to content

Commit

Permalink
extra check on normalized original image URL before putting it on the…
Browse files Browse the repository at this point in the history
… imgopt URL to avoid faulty image url's being sent over for optimization.
  • Loading branch information
futtta committed Mar 11, 2021
1 parent 7969d96 commit e3099e0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions classes/autoptimizeImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,13 @@ private function build_imgopt_url( $orig_url, $width = 0, $height = 0 )
return $filtered_url;
}

$orig_url = $this->normalize_img_url( $orig_url );
$normalized_url = $this->normalize_img_url( $orig_url );

// if the URL is ascii we check if we have a real URL with filter_var (which only works on ascii url's) and if not a real URL we return the original one.
if ( apply_filters( 'autoptimize_filter_imgopt_check_normalized_url', true ) && ! preg_match( '/[^\x20-\x7e]/', $normalized_url ) && false === filter_var( $normalized_url, FILTER_VALIDATE_URL ) ) {
return $orig_url;
}

$imgopt_base_url = $this->get_imgopt_base_url();
$imgopt_size = '';

Expand All @@ -476,7 +482,7 @@ private function build_imgopt_url( $orig_url, $width = 0, $height = 0 )
$imgopt_size .= ',h_' . $height;
}

$url = $imgopt_base_url . $imgopt_size . '/' . $orig_url;
$url = $imgopt_base_url . $imgopt_size . '/' . $normalized_url;

return $url;
}
Expand Down

0 comments on commit e3099e0

Please sign in to comment.