From: Jérémy Benoist Date: Thu, 5 Jul 2018 12:15:50 +0000 (+0000) Subject: Merge pull request #3684 from Simounet/fix/empty-image-download-error X-Git-Tag: 2.3.4~31 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=18167b9a249b679e1226f04c0f05a7489b90d4f7;hp=e586d65b64089fc1cc230a18c470aae3f45f91a6;p=github%2Fwallabag%2Fwallabag.git Merge pull request #3684 from Simounet/fix/empty-image-download-error Fix image downloading on null image path --- diff --git a/src/Wallabag/CoreBundle/Helper/DownloadImages.php b/src/Wallabag/CoreBundle/Helper/DownloadImages.php index 9c9452dd..f91cdf5e 100644 --- a/src/Wallabag/CoreBundle/Helper/DownloadImages.php +++ b/src/Wallabag/CoreBundle/Helper/DownloadImages.php @@ -85,6 +85,10 @@ class DownloadImages */ public function processSingleImage($entryId, $imagePath, $url, $relativePath = null) { + if (null === $imagePath) { + return false; + } + if (null === $relativePath) { $relativePath = $this->getRelativePath($entryId); } diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 51ab1bcd..faa803fa 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php @@ -204,4 +204,27 @@ class DownloadImagesTest extends TestCase $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced'); } + + public function testProcessImageWithNullPath() + { + $client = new Client(); + + $mock = new Mock([ + new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), + ]); + + $client->getEmitter()->attach($mock); + + $logHandler = new TestHandler(); + $logger = new Logger('test', [$logHandler]); + + $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); + + $res = $download->processSingleImage( + 123, + null, + 'https://framablog.org/2018/06/30/engagement-atypique/' + ); + $this->assertFalse($res); + } }