[FOLLOWUP][BUGFIX] ImageViewHelper should catch exceptions 23/45123/3
authorBenni Mack <benni@typo3.org>
Fri, 4 Dec 2015 08:39:49 +0000 (09:39 +0100)
committerFrank Nägler <frank.naegler@typo3.org>
Fri, 4 Dec 2015 10:22:32 +0000 (11:22 +0100)
The Uri/ImageViewHelper should catch exceptions as well.

Releases: master
Resolves: #71686
Change-Id: I63d472070cd2e9f8db28c646684ce0c32b1c08e1
Reviewed-on: https://review.typo3.org/45123
Reviewed-by: Andreas Allacher <andreas.allacher@gmx.at>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php

index 513496b..7c13aed 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
  * Public License for more details.                                       *
  *                                                                        */
 
+use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
 use TYPO3\CMS\Core\Resource\FileInterface;
 use TYPO3\CMS\Core\Resource\FileReference;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -63,7 +64,7 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
  * Could not get image resource for "NonExistingImage.png".
  * </output>
  */
-class ImageViewHelper extends AbstractViewHelper  implements CompilableInterface
+class ImageViewHelper extends AbstractViewHelper implements CompilableInterface
 {
     /**
      * Resizes the image (if required) and returns its path. If the image was not resized, the path will be equal to $src
@@ -123,24 +124,29 @@ class ImageViewHelper extends AbstractViewHelper  implements CompilableInterface
             throw new Exception('You must either specify a string src or a File object.', 1382284105);
         }
 
-        $imageService = self::getImageService();
-        $image = $imageService->getImage($src, $image, $treatIdAsReference);
+        try {
+            $imageService = self::getImageService();
+            $image = $imageService->getImage($src, $image, $treatIdAsReference);
 
-        if ($crop === null) {
-            $crop = $image instanceof FileReference ? $image->getProperty('crop') : null;
-        }
+            if ($crop === null) {
+                $crop = $image instanceof FileReference ? $image->getProperty('crop') : null;
+            }
 
-        $processingInstructions = array(
-            'width' => $arguments['width'],
-            'height' => $arguments['height'],
-            'minWidth' => $arguments['minWidth'],
-            'minHeight' => $arguments['minHeight'],
-            'maxWidth' => $arguments['maxWidth'],
-            'maxHeight' => $arguments['maxHeight'],
-            'crop' => $crop,
-        );
-        $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions);
-        return $imageService->getImageUri($processedImage, $absolute);
+            $processingInstructions = array(
+                'width' => $arguments['width'],
+                'height' => $arguments['height'],
+                'minWidth' => $arguments['minWidth'],
+                'minHeight' => $arguments['minHeight'],
+                'maxWidth' => $arguments['maxWidth'],
+                'maxHeight' => $arguments['maxHeight'],
+                'crop' => $crop,
+            );
+            $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions);
+            return $imageService->getImageUri($processedImage, $absolute);
+        } catch (ResourceDoesNotExistException $e) {
+        } catch (\UnexpectedValueException $e) {
+        }
+        return '';
     }
 
     /**