From 3fbbe0d9f1887d939fdb56733612f8ab0971deaf Mon Sep 17 00:00:00 2001 From: Simounet Date: Sun, 3 Jun 2018 22:52:48 +0200 Subject: [PATCH] Fix image downloading on null image path --- .../CoreBundle/Helper/DownloadImages.php | 4 ++++ .../CoreBundle/Helper/DownloadImagesTest.php | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) 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); + } } -- 2.41.0