Skip to content

Commit

Permalink
Fixes #872 Prevent fatal error if returned extension value is false (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
remyperona authored Apr 19, 2024
1 parent e2f5834 commit a5b7820
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 2 additions & 3 deletions classes/Optimization/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,9 @@ public function get_mime_type() {
/**
* Get the file extension.
*
* @since 1.9
* @author Grégory Viguier
* @since 1.9
*
* @return string|null
* @return string|false
*/
public function get_extension() {
return $this->get_file_type()->ext;
Expand Down
7 changes: 6 additions & 1 deletion classes/Optimization/Process/AbstractProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,12 @@ public function optimize_size( $size, $optimization_level = null ) {
// This file type is not supported.
$extension = $file->get_extension();

if ( '' === $extension ) {
if ( ! $extension ) {
$response = new WP_Error(
'extension_not_mime',
__( 'This file has an extension that does not match a mime type.', 'imagify' )
);
} elseif ( '' === $extension ) {
$response = new WP_Error(
'no_extension',
__( 'With no extension, this file cannot be optimized.', 'imagify' )
Expand Down

0 comments on commit a5b7820

Please sign in to comment.