aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper/DownloadImages.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/DownloadImages.php')
-rw-r--r--src/Wallabag/CoreBundle/Helper/DownloadImages.php17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/DownloadImages.php b/src/Wallabag/CoreBundle/Helper/DownloadImages.php
index 9c9452dd..cc3dcfce 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 }
@@ -181,7 +185,7 @@ class DownloadImages
181 * 185 *
182 * @return array An array of urls 186 * @return array An array of urls
183 */ 187 */
184 protected function getSrcsetUrls(Crawler $imagesCrawler) 188 private function getSrcsetUrls(Crawler $imagesCrawler)
185 { 189 {
186 $urls = []; 190 $urls = [];
187 $iterator = $imagesCrawler 191 $iterator = $imagesCrawler
@@ -189,9 +193,14 @@ class DownloadImages
189 while ($iterator->valid()) { 193 while ($iterator->valid()) {
190 $srcsetAttribute = $iterator->current()->getAttribute('srcset'); 194 $srcsetAttribute = $iterator->current()->getAttribute('srcset');
191 if ('' !== $srcsetAttribute) { 195 if ('' !== $srcsetAttribute) {
192 $srcset = array_map('trim', explode(',', $srcsetAttribute)); 196 // Couldn't start with " OR ' OR a white space
197 // Could be one or more white space
198 // Must be one or more digits followed by w OR x
199 $pattern = "/(?:[^\"'\s]+\s*(?:\d+[wx])+)/";
200 preg_match_all($pattern, $srcsetAttribute, $matches);
201 $srcset = \call_user_func_array('array_merge', $matches);
193 $srcsetUrls = array_map(function ($src) { 202 $srcsetUrls = array_map(function ($src) {
194 return explode(' ', $src)[0]; 203 return trim(explode(' ', $src, 2)[0]);
195 }, $srcset); 204 }, $srcset);
196 $urls = array_merge($srcsetUrls, $urls); 205 $urls = array_merge($srcsetUrls, $urls);
197 } 206 }
@@ -299,7 +308,7 @@ class DownloadImages
299 $this->logger->debug('DownloadImages: Checking extension (alternative)', ['ext' => $ext]); 308 $this->logger->debug('DownloadImages: Checking extension (alternative)', ['ext' => $ext]);
300 } 309 }
301 310
302 if (!in_array($ext, ['jpeg', 'jpg', 'gif', 'png'], true)) { 311 if (!\in_array($ext, ['jpeg', 'jpg', 'gif', 'png'], true)) {
303 $this->logger->error('DownloadImages: Processed image with not allowed extension. Skipping: ' . $imagePath); 312 $this->logger->error('DownloadImages: Processed image with not allowed extension. Skipping: ' . $imagePath);
304 313
305 return false; 314 return false;