Bug #62267
closedgetImgResource some returns urlencoded file path, sometimes not
0%
Description
Since introduction of FAL ContentObjectRenderer::getImgResource() may return either urlencoded or non-urlencoded result depending on the source file.
If the source file is not in FAL (for example, you use "import." from typo3temp or your own ext) or the source is GIFBUILDER, the third element of the returned result will not be encoded. If the file is in FAL, the returned result will be encoded (it uses getPublicUrl() from FAL). As a result you never know whether you have to urlencode $result3 or not. Try with file names that contain German characters.
Relevant pieces of code are below.
Near line 5306, where the encoded result will be set
if ($processedFileObject->isProcessed() && !isset($GLOBALS['TSFE']->tmpl->fileCache[$hash])) { $GLOBALS['TSFE']->tmpl->fileCache[$hash] = array( 0 => $processedFileObject->getProperty('width'), 1 => $processedFileObject->getProperty('height'), 2 => $processedFileObject->getExtension(), 3 => $processedFileObject->getPublicUrl(), 'origFile' => $fileObject->getPublicUrl(), 'origFile_mtime' => $fileObject->getModificationTime(), // This is needed by \TYPO3\CMS\Frontend\Imaging\GifBuilder, // in order for the setup-array to create a unique filename hash. 'originalFile' => $fileObject, 'processedFile' => $processedFileObject, 'fileCacheHash' => $hash ); } $imageResource = $GLOBALS['TSFE']->tmpl->fileCache[$hash];
Near line 5328 (not encoded):
if (!isset($imageResource)) { $theImage = $GLOBALS['TSFE']->tmpl->getFileName($file); if ($theImage) { $gifCreator = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder'); /** @var $gifCreator GifBuilder */ $gifCreator->init(); $info = $gifCreator->imageMagickConvert($theImage, 'WEB'); $info['origFile'] = $theImage; // This is needed by \TYPO3\CMS\Frontend\Imaging\GifBuilder, ln 100ff in order for the setup-array to create a unique filename hash. $info['origFile_mtime'] = @filemtime($theImage); $imageResource = $info; } }
Than in imageMagicConvert():
$output = $this->absPrefix . $this->tempPath . 'pics/' . $this->filenamePrefix . $theOutputName . '.' . $newExt; // Register temporary filename: $GLOBALS['TEMP_IMAGES_ON_PAGE'][] = $output; if ($this->dontCheckForExistingTempFile || !$this->file_exists_typo3temp_file($output, $imagefile)) { $this->imageMagickExec($imagefile, $output, $command, $frame); } if (file_exists($output)) { $info[3] = $output;
As you see, it is a plain file name, not an encoded URL.
Originally the third element was not supposed to be encoded.
Updated by Frans Saris about 10 years ago
I think we should go for encoding the result in all pleases. Despite the fact that it wasn't done before.
Updated by Dmitry Dulepov about 10 years ago
I really like when people say "I think ... because ...", not just "I think..." ;)
Updated by Frans Saris about 10 years ago
Because getPublicUrl() is intended to be used in "public" scope my first thought was to have all the same and since you mentioned that use-case as first (also FAL is the way to go for further development) my first thought was, this should be the way to go :).
But now I gave it a second look. Maybe we should investigate the use-cases for the results of this/these functions.
$file->getPublicUrl() is intended to be used in public context (direct in HTML output) and not for further processing like now is done sometimes.
This is also because getPublicUrl() returns a link to a eID script for local but non public available storages and probably most other storage types.
Do you know if the output of $info3 is intended to be used for further processing or only for linking to the image in "public" scope.
Did you encounter the encoding problem in the core itself of using public API in your own code?
Had also a closer look at what the value of $info should be. The phpDoc of \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::getImgResource() states it's a file name. But that in only true for local public storages when $file->getPublicUrl() is used.
So even if we manage to urldecode the $this->getPublicUrl() outcome the result is still not always what it originally supposed to be.
Giving it a second thought I'm not sure how to proceed.
Updated by Susanne Moog about 7 years ago
- Category changed from Content Rendering to File Abstraction Layer (FAL)
Updated by Christian Kuhn almost 7 years ago
- Status changed from New to Rejected