diff options
author | Simounet <contact@simounet.net> | 2018-06-03 22:52:48 +0200 |
---|---|---|
committer | Simounet <contact@simounet.net> | 2018-07-05 11:40:51 +0200 |
commit | 3fbbe0d9f1887d939fdb56733612f8ab0971deaf (patch) | |
tree | 7e7191a4ed794eb9043361499bdf9c704018c488 | |
parent | e586d65b64089fc1cc230a18c470aae3f45f91a6 (diff) | |
download | wallabag-3fbbe0d9f1887d939fdb56733612f8ab0971deaf.tar.gz wallabag-3fbbe0d9f1887d939fdb56733612f8ab0971deaf.tar.zst wallabag-3fbbe0d9f1887d939fdb56733612f8ab0971deaf.zip |
Fix image downloading on null image path
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/DownloadImages.php | 4 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | 23 |
2 files changed, 27 insertions, 0 deletions
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 | |||
85 | */ | 85 | */ |
86 | public function processSingleImage($entryId, $imagePath, $url, $relativePath = null) | 86 | public function processSingleImage($entryId, $imagePath, $url, $relativePath = null) |
87 | { | 87 | { |
88 | if (null === $imagePath) { | ||
89 | return false; | ||
90 | } | ||
91 | |||
88 | if (null === $relativePath) { | 92 | if (null === $relativePath) { |
89 | $relativePath = $this->getRelativePath($entryId); | 93 | $relativePath = $this->getRelativePath($entryId); |
90 | } | 94 | } |
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 | |||
204 | 204 | ||
205 | $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced'); | 205 | $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced'); |
206 | } | 206 | } |
207 | |||
208 | public function testProcessImageWithNullPath() | ||
209 | { | ||
210 | $client = new Client(); | ||
211 | |||
212 | $mock = new Mock([ | ||
213 | new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
214 | ]); | ||
215 | |||
216 | $client->getEmitter()->attach($mock); | ||
217 | |||
218 | $logHandler = new TestHandler(); | ||
219 | $logger = new Logger('test', [$logHandler]); | ||
220 | |||
221 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | ||
222 | |||
223 | $res = $download->processSingleImage( | ||
224 | 123, | ||
225 | null, | ||
226 | 'https://framablog.org/2018/06/30/engagement-atypique/' | ||
227 | ); | ||
228 | $this->assertFalse($res); | ||
229 | } | ||
207 | } | 230 | } |