diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index fc6fc933ae..8f9b43cb89 100644 --- a/src/wp-includes/class-wp-image-editor-imagick.php +++ b/src/wp-includes/class-wp-image-editor-imagick.php @@ -146,10 +146,10 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { try { $this->image = new Imagick(); - $file_parts = pathinfo( $this->file ); + $file_extension = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) ); $filename = $this->file; - if ( 'pdf' == strtolower( $file_parts['extension'] ) ) { + if ( 'pdf' == $file_extension ) { $filename = $this->pdf_setup(); } diff --git a/tests/phpunit/data/images/test-image-no-extension b/tests/phpunit/data/images/test-image-no-extension new file mode 100644 index 0000000000..8fad364479 Binary files /dev/null and b/tests/phpunit/data/images/test-image-no-extension differ diff --git a/tests/phpunit/tests/image/editor_gd.php b/tests/phpunit/tests/image/editor_gd.php index 21f54656f1..ecb599e839 100644 --- a/tests/phpunit/tests/image/editor_gd.php +++ b/tests/phpunit/tests/image/editor_gd.php @@ -542,4 +542,15 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { unlink( $save_to_file ); } + + /** + * Test WP_Image_Editor_GD handles extension-less images + * @ticket 39195 + */ + public function test_image_non_existent_extension() { + $image_editor = new WP_Image_Editor_GD( DIR_TESTDATA.'/images/test-image-no-extension' ); + $result = $image_editor->load(); + + $this->assertTrue( $result ); + } } diff --git a/tests/phpunit/tests/image/editor_imagick.php b/tests/phpunit/tests/image/editor_imagick.php index d1766b9ff0..c475201c41 100644 --- a/tests/phpunit/tests/image/editor_imagick.php +++ b/tests/phpunit/tests/image/editor_imagick.php @@ -531,4 +531,15 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0, 0 ), $pre_rotate_alpha ); unlink( $save_to_file ); } + + /** + * Test WP_Image_Editor_Imagick handles extension-less images + * @ticket 39195 + */ + public function test_image_non_existent_extension() { + $image_editor = new WP_Image_Editor_Imagick( DIR_TESTDATA.'/images/test-image-no-extension' ); + $result = $image_editor->load(); + + $this->assertTrue( $result ); + } }