Project

General

Profile

Bug #100205 » 100205.patch

Possible solution for using Symfony Finder - Benjamin Serfhos, 2023-03-17 15:58

View differences:

typo3/sysext/core/Classes/TypoScript/IncludeTree/TreeFromLineStreamBuilder.php
namespace TYPO3\CMS\Core\TypoScript\IncludeTree;
use Symfony\Component\Finder\Finder;
use TYPO3\CMS\Core\Resource\Security\FileNameValidator;
use TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\AtImportInclude;
use TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\ConditionElseInclude;
......
$this->processAtImport($fileSuffix, $node, $atImportValueToken, $atImportLine, true);
return;
}
if (!$directoryExists) {
// Absolute directory. There is nothing to import if the directory does not exist.
return;
}
$filePattern = basename($absoluteFileName);
if (!str_contains($filePattern, '*')) {
return;
......
} elseif (str_ends_with($filePattern, '*.' . $fileSuffix)) {
$filePattern = mb_substr($filePattern, 0, -1 * (strlen($fileSuffix) + 2));
}
$filesAndDirs = scandir($directory);
foreach ($filesAndDirs as $potentialInclude) {
if (!str_starts_with($potentialInclude, $filePattern)
|| !str_ends_with($potentialInclude, '.' . $fileSuffix)
|| is_dir($directory . $potentialInclude)
|| !$this->fileNameValidator->isValid($directory . $potentialInclude)
) {
try {
$finder = new Finder();
$finder
// no recursive mode on purpose
->depth(0)
// no directories should be fetched
->files()
->in($directory)
->name($filePattern)
->sortByName();
} catch (\InvalidArgumentException $e) {
return;
}
foreach ($finder as $fileObject) {
if (!$this->fileNameValidator->isValid($fileObject->getFilename())) {
continue;
}
$singleAbsoluteFileName = $directory . $potentialInclude;
$identifier = rtrim(dirname($atImportValue), '/') . '/' . $potentialInclude;
$this->addSingleAtImportFile($node, $singleAbsoluteFileName, $identifier, $atImportLine);
$identifier = rtrim(dirname($atImportValue), '/') . '/' . $fileObject->getFilename();
$this->addSingleAtImportFile($node, $fileObject->getPathname(), $identifier, $atImportLine);
$this->addStaticMagicFromGlobals($node, $identifier);
}
} elseif (!$tryRelative) {
(2-2/2)