From c41a10ecb18ee64b66b6c76ef2d5161a34a45dc0 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Fri, 16 Dec 2016 05:38:41 +0000 Subject: [PATCH] PDF Images: Avoid a PHP Warning when attempting to process a file without an extension. Props chandrapatel for initial patch. Merges [39580] to the 4.7 branch. Fixes #39195. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@39607 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-image-editor-imagick.php | 4 ++-- tests/phpunit/data/images/test-image-no-extension | Bin 0 -> 524 bytes tests/phpunit/tests/image/editor_gd.php | 11 +++++++++++ tests/phpunit/tests/image/editor_imagick.php | 11 +++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/data/images/test-image-no-extension 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 0000000000000000000000000000000000000000..8fad364479d96df7f659438ba45ef2dcc76d12ae GIT binary patch literal 524 zcmZ?wbhEHbG-5DfxXJ(mTwGitA|f&}GRn%zT3TAh#>O@_HqOq@zP`S}!ND;xF^P$Z z85tQRB_-9>)y>V#ot>Q%Cr+F_d-jqgOIEE~wPnkeojZ3PIdbI8nKPF!U%q$m-s8uQ zU%h(u>C>lw|Nen(pdq37lZBIkL4iRBWCzGk3~c`o^cQ&ONcEpsQgkxMYW{^4C0=Wz z*56q3ZP&@1)m)9wwVyID2p3%`)LSuM?x18rrMY@B!=ZB~PZ*_YJS7;ID|wncxEO>u ziy37*UDFul#480Rx$rY|$g>nP&vGt`lNYKKSuDc9?kvYx%(l30l{0Up#3V@uCReFS zu1VYs{BG=((oM4IGH#-kd`$ujoE~lIQ)}A9JgyWAm0e)*Oe=npe}YT&&D(c%#dlK< z)PMb2ox;Pw#`E{z|G!Vp7%pAvtkdLaaW?XU>Y;sV&z`wlO49HZPAcw6ZCtjNbD`zF zO+P+9S>hnq9j3=P;rWq=GUnkE7$rWp+?&G{_F>M#mnx4WHJNM{7W^o4Yc%Tk^-sp( jhD+*R2A}STj@0#MSFDcMoOSoq*45Y7CkV4LGFSru!Q!!l literal 0 HcmV?d00001 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 ); + } }