Skip to content

Commit

Permalink
[BUGFIX] Handle getFileContents in LocalDriver better
Browse files Browse the repository at this point in the history
The method getFileContents has return value string. But since
there is no guarantee that the file exists before calling
file_get_contents, a call to is_readable has been added.
This handles both the PHP Warning and ensures type correctness.

Resolves: #99926
Releases: main, 11.5
Change-Id: I9786a6737d7e3b0c3d04272364d868fd4101307c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77989
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
  • Loading branch information
Thomas Hohn authored and lolli42 committed Mar 1, 2023
1 parent a522211 commit 23ada80
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
Expand Up @@ -1351,12 +1351,12 @@ public function createFile($fileName, $parentFolderIdentifier)
* processing resources and money) for large files.
*
* @param string $fileIdentifier
* @return string The file contents
* @return string The file contents if file exists and else empty string
*/
public function getFileContents($fileIdentifier)
{
$filePath = $this->getAbsolutePath($fileIdentifier);
return file_get_contents($filePath);
return is_readable($filePath) ? (string)file_get_contents($filePath) : '';
}

/**
Expand Down

0 comments on commit 23ada80

Please sign in to comment.