aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-06-01 22:50:33 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-06-01 22:50:33 +0200
commitfcad69a427de7ce4f65cbf53bcf778e561959807 (patch)
tree00f7fb88c0a396c03fcd5d0b1744f96f862d0371
parent590151680538ea1edfef9053da476cd92c6944c4 (diff)
downloadwallabag-fcad69a427de7ce4f65cbf53bcf778e561959807.tar.gz
wallabag-fcad69a427de7ce4f65cbf53bcf778e561959807.tar.zst
wallabag-fcad69a427de7ce4f65cbf53bcf778e561959807.zip
Replace images with &
Images with `&` in the path weren’t well replaced because they might be with `&amp;` in the html instead. Replacing `&` with `&amp;` fix the problem.
-rw-r--r--src/Wallabag/CoreBundle/Helper/DownloadImages.php8
-rw-r--r--tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php24
2 files changed, 28 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/DownloadImages.php b/src/Wallabag/CoreBundle/Helper/DownloadImages.php
index 0d330d2a..f7c26a38 100644
--- a/src/Wallabag/CoreBundle/Helper/DownloadImages.php
+++ b/src/Wallabag/CoreBundle/Helper/DownloadImages.php
@@ -66,6 +66,12 @@ class DownloadImages
66 continue; 66 continue;
67 } 67 }
68 68
69 // if image contains "&"" and we can't find it in the html
70 // it might be because it's encoded as &amp;
71 if (false !== stripos($image, '&') && false === stripos($html, $image)) {
72 $image = str_replace('&', '&amp;', $image);
73 }
74
69 $html = str_replace($image, $imagePath, $html); 75 $html = str_replace($image, $imagePath, $html);
70 } 76 }
71 77
@@ -114,7 +120,7 @@ class DownloadImages
114 $ext = $this->mimeGuesser->guess($res->getHeader('content-type')); 120 $ext = $this->mimeGuesser->guess($res->getHeader('content-type'));
115 $this->logger->debug('DownloadImages: Checking extension', ['ext' => $ext, 'header' => $res->getHeader('content-type')]); 121 $this->logger->debug('DownloadImages: Checking extension', ['ext' => $ext, 'header' => $res->getHeader('content-type')]);
116 if (!in_array($ext, ['jpeg', 'jpg', 'gif', 'png'], true)) { 122 if (!in_array($ext, ['jpeg', 'jpg', 'gif', 'png'], true)) {
117 $this->logger->error('DownloadImages: Processed image with not allowed extension. Skipping '.$imagePath); 123 $this->logger->error('DownloadImages: Processed image with not allowed extension. Skipping: '.$imagePath);
118 124
119 return false; 125 return false;
120 } 126 }
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
index 85f12d87..9125f8dc 100644
--- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
@@ -12,7 +12,24 @@ use GuzzleHttp\Stream\Stream;
12 12
13class DownloadImagesTest extends \PHPUnit_Framework_TestCase 13class DownloadImagesTest extends \PHPUnit_Framework_TestCase
14{ 14{
15 public function testProcessHtml() 15 public function dataForSuccessImage()
16 {
17 return [
18 'imgur' => [
19 '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>',
20 'http://imgur.com/gallery/WxtWY',
21 ],
22 'image with &' => [
23 '<div><img src="https://i2.wp.com/www.tvaddons.ag/wp-content/uploads/2017/01/Screen-Shot-2017-01-07-at-10.17.40-PM.jpg?w=640&amp;ssl=1" /></div>',
24 'https://www.tvaddons.ag/realdebrid-kodi-jarvis/',
25 ],
26 ];
27 }
28
29 /**
30 * @dataProvider dataForSuccessImage
31 */
32 public function testProcessHtml($html, $url)
16 { 33 {
17 $client = new Client(); 34 $client = new Client();
18 35
@@ -27,9 +44,10 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase
27 44
28 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); 45 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
29 46
30 $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY'); 47 $res = $download->processHtml(123, $html, $url);
31 48
32 $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/c638b4c2.png', $res); 49 // this the base path of all image (since it's calculated using the entry id: 123)
50 $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/', $res);
33 } 51 }
34 52
35 public function testProcessHtmlWithBadImage() 53 public function testProcessHtmlWithBadImage()