[BUGFIX] Ensure type safety for ViewHelper calling ImageService 08/59608/2
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 1 Feb 2019 14:59:36 +0000 (15:59 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 1 Feb 2019 15:31:21 +0000 (16:31 +0100)
The ImageService::getImage requires a string as first and a boolean as
third parameter. The Image ViewHelpers must respect this requirement.

Resolves: #87619
Relates: #87599
Releases: master
Change-Id: I0d8f57c2bef62dcc6b4d6e6684bbbb1593bff98f
Reviewed-on: https://review.typo3.org/59608
Reviewed-by: Alexander Schnitzler <typo3@alexanderschnitzler.de>
Tested-by: Alexander Schnitzler <typo3@alexanderschnitzler.de>
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Reviewed-by: André Schließer <andy.schliesser@gmail.com>
Tested-by: André Schließer <andy.schliesser@gmail.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/ImageViewHelperTest.php

index 7acff67..156c6af 100644 (file)
@@ -125,7 +125,7 @@ class ImageViewHelper extends AbstractTagBasedViewHelper
         }
 
         try {
-            $image = $this->imageService->getImage($this->arguments['src'], $this->arguments['image'], $this->arguments['treatIdAsReference']);
+            $image = $this->imageService->getImage((string)$this->arguments['src'], $this->arguments['image'], (bool)$this->arguments['treatIdAsReference']);
             $cropString = $this->arguments['crop'];
             if ($cropString === null && $image->hasProperty('crop') && $image->getProperty('crop')) {
                 $cropString = $image->getProperty('crop');
index 932a35b..0267d81 100644 (file)
@@ -71,7 +71,7 @@ class ImageViewHelper extends AbstractViewHelper
      */
     public function initializeArguments()
     {
-        $this->registerArgument('src', 'string', 'src');
+        $this->registerArgument('src', 'string', 'src', false, '');
         $this->registerArgument('treatIdAsReference', 'bool', 'given src argument is a sys_file_reference record', false, false);
         $this->registerArgument('image', 'object', 'image');
         $this->registerArgument('crop', 'string|bool', 'overrule cropping of image (setting to FALSE disables the cropping set in FileReference)');
@@ -97,13 +97,13 @@ class ImageViewHelper extends AbstractViewHelper
      */
     public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
     {
-        $src = $arguments['src'];
+        $src = (string)$arguments['src'];
         $image = $arguments['image'];
-        $treatIdAsReference = $arguments['treatIdAsReference'];
+        $treatIdAsReference = (bool)$arguments['treatIdAsReference'];
         $cropString = $arguments['crop'];
         $absolute = $arguments['absolute'];
 
-        if (($src === null && $image === null) || ($src !== null && $image !== null)) {
+        if (($src === '' && $image === null) || ($src !== '' && $image !== null)) {
             throw new Exception('You must either specify a string src or a File object.', 1460976233);
         }
 
index a1384dd..0e12c97 100644 (file)
@@ -51,6 +51,7 @@ class ImageViewHelperTest extends ViewHelperBaseTestcase
     {
         return [
             [['image' => null]],
+            [['src' => null]],
             [['src' => '']],
             [['src' => 'something', 'image' => 'something']],
         ];