[TASK] Use PathUtility wrappers for basename/dirname 69/47169/18
authorJigal van Hemert <jigal.van.hemert@typo3.org>
Thu, 10 May 2018 19:09:14 +0000 (21:09 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Fri, 11 May 2018 13:48:00 +0000 (15:48 +0200)
Basename and dirname are locale aware and can damage path and file names
if they are used with UTF-8 file/path names while a UTF-8 locale is not
loaded.
The PathUtility wrappers solve this.

Releases: master
Resolves: #74806
Change-Id: Ibe113a1632b4e61ea87ed9a7dc8600bf3535acab
Reviewed-on: https://review.typo3.org/47169
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
37 files changed:
typo3/sysext/backend/Classes/Clipboard/Clipboard.php
typo3/sysext/backend/Classes/Form/FieldControl/InsertClipboard.php
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/belog/Classes/ViewHelpers/FormatDetailsViewHelper.php
typo3/sysext/core/Classes/Cache/Backend/FileBackend.php
typo3/sysext/core/Classes/Cache/Backend/SimpleFileBackend.php
typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Database/ReferenceIndex.php
typo3/sysext/core/Classes/Database/SoftReferenceIndex.php
typo3/sysext/core/Classes/Http/UploadedFile.php
typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
typo3/sysext/core/Classes/Integrity/DatabaseIntegrityCheck.php
typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php
typo3/sysext/core/Classes/Log/Writer/FileWriter.php
typo3/sysext/core/Classes/Package/PackageManager.php
typo3/sysext/core/Classes/Resource/OnlineMedia/Processing/PreviewProcessing.php
typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php
typo3/sysext/core/Classes/Utility/CommandUtility.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Classes/Utility/PathUtility.php
typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest.php
typo3/sysext/extensionmanager/Classes/Utility/FileHandlingUtility.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Classes/Imaging/GifBuilder.php
typo3/sysext/frontend/Classes/Plugin/AbstractPlugin.php
typo3/sysext/impexp/Classes/Controller/ImportExportController.php
typo3/sysext/impexp/Classes/Import.php
typo3/sysext/indexed_search/Classes/FileContentParser.php
typo3/sysext/indexed_search/Classes/Indexer.php
typo3/sysext/install/Classes/Updates/BackendLayoutIconUpdateWizard.php
typo3/sysext/install/Classes/Updates/FrontendUserImageUpdateWizard.php
typo3/sysext/install/Classes/UpgradeAnalysis/DocumentationFile.php
typo3/sysext/lowlevel/Classes/Command/FilesWithMultipleReferencesCommand.php
typo3/sysext/lowlevel/Classes/Command/LostFilesCommand.php
typo3/sysext/lowlevel/Classes/Command/RteImagesCommand.php
typo3/sysext/workspaces/Classes/Service/AdditionalResourceService.php

index eed6b81..a2a5588 100644 (file)
@@ -25,6 +25,7 @@ use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
 
 /**
@@ -556,7 +557,7 @@ class Clipboard
             if (!$this->fileMode) {
                 $str = '<span class="text-muted">' . $str . '</span>';
             } elseif (ExtensionManagementUtility::isLoaded('filelist')) {
-                $str = '<a href="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('file_list', ['id' => dirname($rec)])) . '">' . $str . '</a>';
+                $str = '<a href="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('file_list', ['id' => PathUtility::dirname($rec)])) . '">' . $str . '</a>';
             }
         }
         return $str;
@@ -697,10 +698,10 @@ class Clipboard
             $labelKey = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:mess.' . ($this->currentMode() === 'copy' ? 'copy' : 'move') . ($this->current === 'normal' ? '' : 'cb') . '_' . $type;
             $msg = $this->getLanguageService()->sL($labelKey . ($columnLabel ? '_colPos' : ''));
             if ($table === '_FILE') {
-                $thisRecTitle = basename($rec);
+                $thisRecTitle = PathUtility::basename($rec);
                 if ($this->current === 'normal') {
                     $selItem = reset($clElements);
-                    $selRecTitle = basename($selItem);
+                    $selRecTitle = PathUtility::basename($selItem);
                 } else {
                     $selRecTitle = count($clElements);
                 }
index 0ba25f1..0ef3b11 100644 (file)
@@ -18,6 +18,7 @@ namespace TYPO3\CMS\Backend\Form\FieldControl;
 use TYPO3\CMS\Backend\Form\AbstractNode;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Renders the icon "insert record from clipboard",
@@ -52,7 +53,7 @@ class InsertClipboard extends AbstractNode
             $title = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clipInsert_file'), count($clipboardElements));
             foreach ($clipboardElements as $clipboardElement) {
                 $value = $clipboardElement['value'];
-                $title = 'unescape(' . GeneralUtility::quoteJSvalue(rawurlencode(basename($clipboardElement['title']))) . ')';
+                $title = 'unescape(' . GeneralUtility::quoteJSvalue(rawurlencode(PathUtility::basename($clipboardElement['title']))) . ')';
                 $clipboardOnClick[] = 'setFormValueFromBrowseWin('
                         . GeneralUtility::quoteJSvalue($elementName) . ','
                         . 'unescape(' . GeneralUtility::quoteJSvalue(rawurlencode(str_replace('%20', ' ', $value))) . '),'
index 90cffa2..ecc2447 100644 (file)
@@ -2975,7 +2975,7 @@ class BackendUtility
             $mainParams = ['id' => $mainParams];
         }
         if (!$script) {
-            $script = basename(Environment::getCurrentScript());
+            $script = PathUtility::basename(Environment::getCurrentScript());
         }
 
         if ($routePath = GeneralUtility::_GP('route')) {
index e0cbe65..787224f 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Belog\ViewHelpers;
  */
 
 use TYPO3\CMS\Belog\Domain\Model\LogEntry;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
@@ -78,7 +79,7 @@ class FormatDetailsViewHelper extends AbstractViewHelper
     protected static function stripPathFromFilenames(array $files = [])
     {
         foreach ($files as $key => $file) {
-            $files[$key] = basename($file);
+            $files[$key] = PathUtility::basename($file);
         }
         return $files;
     }
index 0c98c1b..3118a13 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Cache\Backend;
 
 use TYPO3\CMS\Core\Service\OpcodeCacheService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
@@ -126,7 +127,7 @@ class FileBackend extends \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend implem
         if (!is_string($data)) {
             throw new \TYPO3\CMS\Core\Cache\Exception\InvalidDataException('The specified data is of type "' . gettype($data) . '" but a string is expected.', 1204481674);
         }
-        if ($entryIdentifier !== basename($entryIdentifier)) {
+        if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
             throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073032);
         }
         if ($entryIdentifier === '') {
@@ -171,7 +172,7 @@ class FileBackend extends \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend implem
         if ($this->frozen === true) {
             return isset($this->cacheEntryIdentifiers[$entryIdentifier]) ? file_get_contents($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension) : false;
         }
-        if ($entryIdentifier !== basename($entryIdentifier)) {
+        if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
             throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073033);
         }
         $pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
@@ -201,7 +202,7 @@ class FileBackend extends \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend implem
         if ($this->frozen === true) {
             return isset($this->cacheEntryIdentifiers[$entryIdentifier]);
         }
-        if ($entryIdentifier !== basename($entryIdentifier)) {
+        if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
             throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073034);
         }
         return !$this->isCacheFileExpired($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension);
@@ -219,7 +220,7 @@ class FileBackend extends \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend implem
      */
     public function remove($entryIdentifier)
     {
-        if ($entryIdentifier !== basename($entryIdentifier)) {
+        if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
             throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073035);
         }
         if ($entryIdentifier === '') {
@@ -392,7 +393,7 @@ class FileBackend extends \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend implem
             }
             return false;
         }
-        if ($entryIdentifier !== basename($entryIdentifier)) {
+        if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
             throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073036);
         }
         $pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
index 70993b7..59b3732 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Core\Cache\Backend;
 use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Service\OpcodeCacheService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
@@ -217,7 +218,7 @@ class SimpleFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend im
         if (!is_string($data)) {
             throw new \TYPO3\CMS\Core\Cache\Exception\InvalidDataException('The specified data is of type "' . gettype($data) . '" but a string is expected.', 1334756734);
         }
-        if ($entryIdentifier !== basename($entryIdentifier)) {
+        if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
             throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756735);
         }
         if ($entryIdentifier === '') {
@@ -246,7 +247,7 @@ class SimpleFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend im
      */
     public function get($entryIdentifier)
     {
-        if ($entryIdentifier !== basename($entryIdentifier)) {
+        if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
             throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756877);
         }
         $pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
@@ -266,7 +267,7 @@ class SimpleFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend im
      */
     public function has($entryIdentifier)
     {
-        if ($entryIdentifier !== basename($entryIdentifier)) {
+        if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
             throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756878);
         }
         return file_exists($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension);
@@ -283,7 +284,7 @@ class SimpleFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend im
      */
     public function remove($entryIdentifier)
     {
-        if ($entryIdentifier !== basename($entryIdentifier)) {
+        if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
             throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756960);
         }
         if ($entryIdentifier === '') {
@@ -352,7 +353,7 @@ class SimpleFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend im
     public function requireOnce($entryIdentifier)
     {
         $pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
-        if ($entryIdentifier !== basename($entryIdentifier)) {
+        if ($entryIdentifier !== PathUtility::basename($entryIdentifier)) {
             throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073037);
         }
         return file_exists($pathAndFilename) ? require_once $pathAndFilename : false;
index 1d9db36..d56325a 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Core;
  */
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
@@ -402,7 +403,7 @@ class SystemEnvironmentBuilder
      */
     protected static function getRootPathFromScriptPath($scriptPath, $entryPointLevel)
     {
-        $entryScriptDirectory = dirname($scriptPath);
+        $entryScriptDirectory = PathUtility::dirnameDuringBootstrap($scriptPath);
         if ($entryPointLevel > 0) {
             list($rootPath) = GeneralUtility::revExplode('/', $entryScriptDirectory, $entryPointLevel + 1);
         } else {
index 36c5c1d..41111ac 100644 (file)
@@ -2211,7 +2211,7 @@ class DataHandler implements LoggerAwareInterface
                     if ($this->autoVersioningUpdate === true) {
                         foreach ($valueArray as $key => $theFile) {
                             // If it is an already attached file...
-                            if ($theFile === basename($theFile)) {
+                            if ($theFile === PathUtility::basename($theFile)) {
                                 $valueArray[$key] = PATH_site . $tcaFieldConf['uploadfolder'] . '/' . $theFile;
                             }
                         }
@@ -2297,7 +2297,7 @@ class DataHandler implements LoggerAwareInterface
                                         $this->copiedFileMap[$theFile] = $theDestFile;
                                         clearstatcache();
                                         if (!@is_file($theDestFile)) {
-                                            $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, [$theFile, dirname($theDestFile), $recFID], $propArr['event_pid']);
+                                            $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, [$theFile, PathUtility::dirname($theDestFile), $recFID], $propArr['event_pid']);
                                         }
                                     } else {
                                         $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, [$theFile, $theDestFile, $recFID], $propArr['event_pid']);
@@ -2367,7 +2367,7 @@ class DataHandler implements LoggerAwareInterface
                             if (@is_file(PATH_site . $this->alternativeFilePath[$theFile])) {
                                 $theFile = PATH_site . $this->alternativeFilePath[$theFile];
                             } elseif (@is_file($theFile)) {
-                                $dest = dirname(PATH_site . $this->alternativeFilePath[$theFile]);
+                                $dest = PathUtility::dirname(PATH_site . $this->alternativeFilePath[$theFile]);
                                 if (!@is_dir($dest)) {
                                     GeneralUtility::mkdir_deep($dest);
                                 }
@@ -2390,7 +2390,7 @@ class DataHandler implements LoggerAwareInterface
                                             $this->copiedFileMap[$theFile] = $theDestFile;
                                             clearstatcache();
                                             if (!@is_file($theDestFile)) {
-                                                $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, [$theFile, dirname($theDestFile), $recFID], $propArr['event_pid']);
+                                                $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, [$theFile, PathUtility::dirname($theDestFile), $recFID], $propArr['event_pid']);
                                             }
                                         } else {
                                             $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, [$theFile, $theDestFile, $recFID], $propArr['event_pid']);
@@ -4175,7 +4175,7 @@ class DataHandler implements LoggerAwareInterface
             return;
         }
         foreach ($rteFileRecords as $rteFileRecord) {
-            $filename = basename($rteFileRecord['ref_string']);
+            $filename = PathUtility::basename($rteFileRecord['ref_string']);
             if (!GeneralUtility::isFirstPartOfStr($filename, 'RTEmagicC_')) {
                 continue;
             }
@@ -4189,8 +4189,8 @@ class DataHandler implements LoggerAwareInterface
                 continue;
             }
             // Initialize; Get directory prefix for file and set the original name:
-            $dirPrefix = dirname($rteFileRecord['ref_string']) . '/';
-            $rteOrigName = basename($fileInfo['original']);
+            $dirPrefix = PathUtility::dirname($rteFileRecord['ref_string']) . '/';
+            $rteOrigName = PathUtility::basename($fileInfo['original']);
             // If filename looks like an RTE file, and the directory is in "uploads/", then process as a RTE file!
             if ($rteOrigName && GeneralUtility::isFirstPartOfStr($dirPrefix, 'uploads/') && @is_dir(PATH_site . $dirPrefix)) {
                 // RTE:
@@ -4198,7 +4198,7 @@ class DataHandler implements LoggerAwareInterface
                 $origDestName = $this->fileFunc->getUniqueName($rteOrigName, PATH_site . $dirPrefix);
                 // Create copy file name:
                 $pI = pathinfo($rteFileRecord['ref_string']);
-                $copyDestName = dirname($origDestName) . '/RTEmagicC_' . mb_substr(basename($origDestName), 10) . '.' . $pI['extension'];
+                $copyDestName = PathUtility::dirname($origDestName) . '/RTEmagicC_' . mb_substr(PathUtility::basename($origDestName), 10) . '.' . $pI['extension'];
                 if (!@is_file($copyDestName) && !@is_file($origDestName) && $origDestName === GeneralUtility::getFileAbsFileName($origDestName) && $copyDestName === GeneralUtility::getFileAbsFileName($copyDestName)) {
                     // Making copies:
                     GeneralUtility::upload_copy_move(PATH_site . $fileInfo['original'], $origDestName);
index f4915cd..8b7b960 100644 (file)
@@ -898,7 +898,7 @@ class ReferenceIndex implements LoggerAwareInterface
             if (trim($file)) {
                 $realFile = $destinationFolder . '/' . trim($file);
                 $newValueFile = [
-                    'filename' => basename($file),
+                    'filename' => PathUtility::basename($file),
                     'ID' => md5($realFile),
                     'ID_absFile' => $realFile
                 ];
index e69a24e..994cb5b 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\LinkHandling\LinkService;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Frontend\Service\TypoLinkCodecService;
 
 /**
@@ -176,7 +177,7 @@ class SoftReferenceIndex
                     $elements[$k] = [];
                     $elements[$k]['matchString'] = $v;
                     // If the image seems to be an RTE image, then proceed to set up substitution token:
-                    if (GeneralUtility::isFirstPartOfStr($srcRef, 'uploads/') && preg_match('/^RTEmagicC_/', basename($srcRef))) {
+                    if (GeneralUtility::isFirstPartOfStr($srcRef, 'uploads/') && preg_match('/^RTEmagicC_/', PathUtility::basename($srcRef))) {
                         // Token and substitute value:
                         // Make sure the value we work on is found and will get substituted in the content (Very important that the src-value is not DeHSC'ed)
                         if (strstr($splitContent[$k], $attribs[0]['src'])) {
index 9bb91b4..cda9153 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Core\Http;
 use Psr\Http\Message\StreamInterface;
 use Psr\Http\Message\UploadedFileInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Class UploadedFile which represents one uploaded file, usually coming
@@ -185,7 +186,7 @@ class UploadedFile implements UploadedFileInterface
         }
 
         if (!empty($this->file) && is_uploaded_file($this->file)) {
-            if (GeneralUtility::upload_copy_move($this->file, $targetPath . basename($this->file)) === false) {
+            if (GeneralUtility::upload_copy_move($this->file, $targetPath . PathUtility::basename($this->file)) === false) {
                 throw new \RuntimeException('An error occurred while moving uploaded file', 1436717310);
             }
         } elseif ($this->stream) {
index ce1e9b2..b6c8a51 100644 (file)
@@ -23,6 +23,7 @@ use TYPO3\CMS\Core\Utility\CommandUtility;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Standard graphical functions
@@ -2131,7 +2132,7 @@ class GraphicalFunctions
         $command .= ' -colorspace ' . $this->colorspace;
         $cropscale = $data['crs'] ? 'crs-V' . $data['cropV'] . 'H' . $data['cropH'] : '';
         if ($this->alternativeOutputKey) {
-            $theOutputName = GeneralUtility::shortMD5($command . $cropscale . basename($imagefile) . $this->alternativeOutputKey . '[' . $frame . ']');
+            $theOutputName = GeneralUtility::shortMD5($command . $cropscale . PathUtility::basename($imagefile) . $this->alternativeOutputKey . '[' . $frame . ']');
         } else {
             $theOutputName = GeneralUtility::shortMD5($command . $cropscale . $imagefile . filemtime($imagefile) . '[' . $frame . ']');
         }
@@ -2533,7 +2534,7 @@ class GraphicalFunctions
 
         if (($type === 'IM' || !$type) && $gfxConf['processor_enabled'] && $gfxConf['processor_path_lzw']) {
             // Use temporary file to prevent problems with read and write lock on same file on network file systems
-            $temporaryName = dirname($theFile) . '/' . md5(uniqid('', true)) . '.gif';
+            $temporaryName = PathUtility::dirname($theFile) . '/' . md5(uniqid('', true)) . '.gif';
             // Rename could fail, if a simultaneous thread is currently working on the same thing
             if (@rename($theFile, $temporaryName)) {
                 $cmd = CommandUtility::imageMagickCommand('convert', '"' . $temporaryName . '" "' . $theFile . '"', $gfxConf['processor_path_lzw']);
index c4cc9fe..ace5a16 100644 (file)
@@ -22,6 +22,7 @@ use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Database\RelationHandler;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * This class holds functions used by the TYPO3 backend to check the integrity of the database (The DBint module, 'lowlevel' extension)
@@ -579,9 +580,9 @@ class DatabaseIntegrityCheck
                     $references = 1;
                 }
                 // The directory must be empty (prevents checking of the root directory)
-                $directory = dirname($file);
+                $directory = PathUtility::dirname($file);
                 if ($directory !== '') {
-                    $newCheckFileRefs[$directory][basename($file)] = $references;
+                    $newCheckFileRefs[$directory][PathUtility::basename($file)] = $references;
                 }
             }
         }
index 406f776..ab4c489 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Core\Localization\Parser;
 use TYPO3\CMS\Core\Localization\Exception\FileNotFoundException;
 use TYPO3\CMS\Core\Localization\Exception\InvalidXmlFileException;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Abstract class for XML based parser.
@@ -95,7 +96,7 @@ abstract class AbstractXmlParser implements LocalizationParserInterface
     protected function getLocalizedFileName($fileRef, $language, $sameLocation = false)
     {
         // If $fileRef is already prefixed with "[language key]" then we should return it as is
-        $fileName = basename($fileRef);
+        $fileName = PathUtility::basename($fileRef);
         if (GeneralUtility::isFirstPartOfStr($fileName, $language . '.')) {
             return GeneralUtility::getFileAbsFileName($fileRef);
         }
index 625dfab..74100c2 100644 (file)
@@ -184,7 +184,7 @@ class FileWriter extends AbstractWriter
         if (file_exists($this->logFile)) {
             return;
         }
-        $logFileDirectory = dirname($this->logFile);
+        $logFileDirectory = PathUtility::dirname($this->logFile);
         if (!@is_dir($logFileDirectory)) {
             GeneralUtility::mkdir_deep($logFileDirectory);
             // create .htaccess file if log file is within the site path
index 850a938..ff73545 100644 (file)
@@ -371,8 +371,8 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
 
             /** @var SplFileInfo $fileInfo */
             foreach ($finder as $fileInfo) {
-                $path = dirname($fileInfo->getPathname());
-                $extensionName = basename($path);
+                $path = PathUtility::dirname($fileInfo->getPathname());
+                $extensionName = PathUtility::basename($path);
                 // Fix Windows backslashes
                 // we can't use GeneralUtility::fixWindowsFilePath as we have to keep double slashes for Unit Tests (vfs://)
                 $currentPath = str_replace('\\', '/', $path) . '/';
@@ -871,13 +871,13 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
             $json = file_get_contents($manifestPath . 'composer.json');
             $composerManifest = json_decode($json);
             if (!$composerManifest instanceof \stdClass) {
-                throw new Exception\InvalidPackageManifestException('The composer.json found for extension "' . basename($manifestPath) . '" is invalid!', 1439555561);
+                throw new Exception\InvalidPackageManifestException('The composer.json found for extension "' . PathUtility::basename($manifestPath) . '" is invalid!', 1439555561);
             }
         }
 
         $extensionManagerConfiguration = $this->getExtensionEmConf($manifestPath);
         $composerManifest = $this->mapExtensionManagerConfigurationToComposerManifest(
-            basename($manifestPath),
+            PathUtility::basename($manifestPath),
             $extensionManagerConfiguration,
             $composerManifest ?: new \stdClass()
         );
@@ -895,7 +895,7 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
      */
     protected function getExtensionEmConf($packagePath)
     {
-        $packageKey = basename($packagePath);
+        $packageKey = PathUtility::basename($packagePath);
         $_EXTKEY = $packageKey;
         $path = $packagePath . 'ext_emconf.php';
         $EM_CONF = null;
@@ -1041,7 +1041,7 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
             throw new Exception\InvalidPackageManifestException('Invalid composer manifest in package path: ' . $packagePath, 1348146451);
         }
         if (isset($manifest->type) && substr($manifest->type, 0, 10) === 'typo3-cms-') {
-            $packageKey = basename($packagePath);
+            $packageKey = PathUtility::basename($packagePath);
             return preg_replace('/[^A-Za-z0-9._-]/', '', $packageKey);
         }
         $packageKey = str_replace('/', '.', $manifest->name);
index efc3d26..23e467e 100644 (file)
@@ -26,6 +26,7 @@ use TYPO3\CMS\Core\Resource\Service\FileProcessingService;
 use TYPO3\CMS\Core\Type\File\ImageInfo;
 use TYPO3\CMS\Core\Utility\CommandUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Frontend\Imaging\GifBuilder;
 
 /**
@@ -150,7 +151,7 @@ class PreviewProcessing
         if (!file_exists($temporaryFileName)) {
             // Create a error image
             $graphicalFunctions = $this->getGraphicalFunctionsObject();
-            $graphicalFunctions->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', basename($originalFileName));
+            $graphicalFunctions->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', PathUtility::basename($originalFileName));
         }
     }
 
@@ -195,7 +196,7 @@ class PreviewProcessing
         if (!file_exists($temporaryFileName)) {
             // Create a error image
             $graphicalFunctions = $this->getGraphicalFunctionsObject();
-            $graphicalFunctions->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', basename($originalFileName));
+            $graphicalFunctions->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', PathUtility::basename($originalFileName));
         }
     }
 
index 5fb7b92..114fdd9 100644 (file)
@@ -989,14 +989,14 @@ class TypoScriptParser
         } else {
             // Apparently this is not a folder, so the restriction
             // is the folder so we restrict into this folder
-            $finder->in(dirname($absoluteFileName));
+            $finder->in(PathUtility::dirname($absoluteFileName));
             if (!is_file($absoluteFileName)
-                && strpos(basename($absoluteFileName), '*') === false
-                && substr(basename($absoluteFileName), -11) !== '.typoscript') {
+                && strpos(PathUtility::basename($absoluteFileName), '*') === false
+                && substr(PathUtility::basename($absoluteFileName), -11) !== '.typoscript') {
                 $absoluteFileName .= '*.typoscript';
             }
-            $finder->name(basename($absoluteFileName));
-            $readableFilePrefix = dirname($filename);
+            $finder->name(PathUtility::basename($absoluteFileName));
+            $readableFilePrefix = PathUtility::dirname($filename);
         }
 
         foreach ($finder as $fileObject) {
index 3202ba6..3e693c5 100644 (file)
@@ -206,7 +206,7 @@ class CommandUtility
             $cmd = @self::exec('which ' . $cmd);
             if (@is_executable($cmd)) {
                 self::$applications[$cmd]['app'] = $cmd;
-                self::$applications[$cmd]['path'] = dirname($cmd) . '/';
+                self::$applications[$cmd]['path'] = PathUtility::dirname($cmd) . '/';
                 self::$applications[$cmd]['valid'] = true;
                 return true;
             }
@@ -361,8 +361,8 @@ class CommandUtility
                     continue;
                 }
                 list($cmd, $cmdPath) = GeneralUtility::trimExplode('=', $val, true, 2);
-                $cmdArr[$cmd]['app'] = basename($cmdPath);
-                $cmdArr[$cmd]['path'] = dirname($cmdPath) . '/';
+                $cmdArr[$cmd]['app'] = PathUtility::basename($cmdPath);
+                $cmdArr[$cmd]['path'] = PathUtility::dirname($cmdPath) . '/';
                 $cmdArr[$cmd]['valid'] = true;
             }
         }
index a294f9f..adf099c 100644 (file)
@@ -2794,7 +2794,7 @@ class GeneralUtility
                 if (defined('TYPO3_PATH_WEB')) {
                     $retVal = $url;
                 } elseif (Environment::getCurrentScript() && defined('PATH_site')) {
-                    $lPath = PathUtility::stripPathSitePrefix(dirname(Environment::getCurrentScript())) . '/';
+                    $lPath = PathUtility::stripPathSitePrefix(PathUtility::dirnameDuringBootstrap(Environment::getCurrentScript())) . '/';
                     $siteUrl = substr($url, 0, -strlen($lPath));
                     if (substr($siteUrl, -1) !== '/') {
                         $siteUrl .= '/';
@@ -3328,7 +3328,7 @@ class GeneralUtility
             self::mkdir_deep($temporaryPath);
         }
         if ($fileSuffix === '') {
-            $tempFileName = $temporaryPath . basename(tempnam($temporaryPath, $filePrefix));
+            $tempFileName = $temporaryPath . PathUtility::basename(tempnam($temporaryPath, $filePrefix));
         } else {
             do {
                 $tempFileName = $temporaryPath . $filePrefix . mt_rand(1, PHP_INT_MAX) . $fileSuffix;
@@ -3404,7 +3404,7 @@ class GeneralUtility
     {
         trigger_error('This method will be removed in TYPO3 v10.0, the functionality has been moved into AbstractXmlParser', E_USER_DEPRECATED);
         // If $fileRef is already prefixed with "[language key]" then we should return it as is
-        $fileName = basename($fileRef);
+        $fileName = PathUtility::basename($fileRef);
         if (self::isFirstPartOfStr($fileName, $language . '.')) {
             return $fileRef;
         }
index 6f874cc..ec846d6 100644 (file)
@@ -30,7 +30,7 @@ class PathUtility
      */
     public static function getRelativePathTo($targetPath)
     {
-        return self::getRelativePath(dirname(Environment::getCurrentScript()), $targetPath);
+        return self::getRelativePath(self::dirname(Environment::getCurrentScript()), $targetPath);
     }
 
     /**
@@ -52,7 +52,7 @@ class PathUtility
             return $targetPath;
         } else {
             // Make an absolute path out of it
-            $targetPath = GeneralUtility::resolveBackPath(dirname(Environment::getCurrentScript()) . '/' . $targetPath);
+            $targetPath = GeneralUtility::resolveBackPath(self::dirname(Environment::getCurrentScript()) . '/' . $targetPath);
             $targetPath = self::stripPathSitePrefix($targetPath);
             if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
                 $targetPath = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . $targetPath;
@@ -262,6 +262,36 @@ class PathUtility
         return $result;
     }
 
+    /**
+     * Returns parent directory's path
+     * Early during bootstrap there is no TYPO3_CONF_VARS yet so the setting for the system locale
+     * is also unavailable. The path of the parent directory is determined with a regular expression
+     * to avoid issues with locales.
+     *
+     * @param string $path
+     *
+     * @return string
+     */
+    public static function dirnameDuringBootstrap($path): string
+    {
+        return preg_replace('#(.*)(/|\\\\)([^\\\\/]+)$#', '$1', $path);
+    }
+
+    /**
+     * Returns filename part of a path
+     * Early during bootstrap there is no TYPO3_CONF_VARS yet so the setting for the system locale
+     * is also unavailable. The filename part is determined with a regular expression to avoid issues
+     * with locales.
+     *
+     * @param string $path
+     *
+     * @return string
+     */
+    public static function basenameDuringBootstrap($path): string
+    {
+        return preg_replace('#([^\\\\/]+)$#', '$1', $path);
+    }
+
     /*********************
      *
      * Cleaning methods
index 84145de..97f12a3 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource;
  */
 
 use TYPO3\CMS\Core\Resource\ResourceCompressor;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Testcase for the ResourceCompressor class
@@ -395,7 +396,7 @@ class ResourceCompressorTest extends BaseTestCase
         // we have to fix relative paths, if we aren't working on a file in our target directory
         $relativeFilename = str_replace(PATH_site, '', $cssFile);
         if (strpos($relativeFilename, $this->subject->_get('targetDirectory')) === false) {
-            $compressedCss = $this->subject->_call('cssFixRelativeUrlPaths', $compressedCss, dirname($relativeFilename) . '/');
+            $compressedCss = $this->subject->_call('cssFixRelativeUrlPaths', $compressedCss, PathUtility::dirname($relativeFilename) . '/');
         }
         $this->assertEquals(file_get_contents($expected), $compressedCss, 'Group of file CSS assets optimized correctly.');
     }
index 4251ef3..38ca3f3 100644 (file)
@@ -506,7 +506,7 @@ class FileHandlingUtility implements \TYPO3\CMS\Core\SingletonInterface
     public function sendZipFileToBrowserAndDelete($fileName, $downloadName = '')
     {
         if ($downloadName === '') {
-            $downloadName = basename($fileName, '.zip');
+            $downloadName = PathUtility::basename($fileName, '.zip');
         }
         header('Content-Type: application/zip');
         header('Content-Length: ' . filesize($fileName));
index ae43cf9..55d96de 100644 (file)
@@ -52,6 +52,7 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\HttpUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3\CMS\Frontend\Http\UrlHandlerInterface;
@@ -4160,7 +4161,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
         } else {
             $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
             // This is a hack to work around ___FILE___ resolving symbolic links
-            $PATH_site_real = dirname(realpath(PATH_site . 'typo3')) . '/';
+            $PATH_site_real = PathUtility::dirname(realpath(PATH_site . 'typo3')) . '/';
             $file = $trace[0]['file'];
             if (strpos($file, $PATH_site_real) === 0) {
                 $file = str_replace($PATH_site_real, '', $file);
index fb0097a..85fdf7c 100644 (file)
@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\File\BasicFileUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 
 /**
@@ -189,7 +190,7 @@ class GifBuilder extends GraphicalFunctions
                         case 'IMAGE':
                             $fileInfo = $this->getResource($conf['file'], $conf['file.']);
                             if ($fileInfo) {
-                                $this->combinedFileNames[] = preg_replace('/\\.[[:alnum:]]+$/', '', basename($fileInfo[3]));
+                                $this->combinedFileNames[] = preg_replace('/\\.[[:alnum:]]+$/', '', PathUtility::basename($fileInfo[3]));
                                 if ($fileInfo['processedFile'] instanceof ProcessedFile) {
                                     // Use processed file, if a FAL file has been processed by GIFBUILDER (e.g. scaled/cropped)
                                     $this->setup[$theKey . '.']['file'] = $fileInfo['processedFile']->getForLocalProcessing(false);
@@ -582,7 +583,7 @@ class GifBuilder extends GraphicalFunctions
         }
         if ((string)$conf['text'] != '') {
             // Char range map thingie:
-            $fontBaseName = basename($conf['fontFile']);
+            $fontBaseName = PathUtility::basename($conf['fontFile']);
             if (is_array($this->charRangeMap[$fontBaseName])) {
                 // Initialize splitRendering array:
                 if (!is_array($conf['splitRendering.'])) {
index efa083c..18dea0d 100644 (file)
@@ -25,6 +25,7 @@ use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
@@ -978,7 +979,7 @@ class AbstractPlugin
         }
 
         if ($languageFilePath === '' && $this->scriptRelPath) {
-            $languageFilePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xlf';
+            $languageFilePath = 'EXT:' . $this->extKey . '/' . PathUtility::dirname($this->scriptRelPath) . '/locallang.xlf';
         }
         if ($languageFilePath !== '') {
             /** @var $languageFactory LocalizationFactory */
index 03371b9..5eff184 100644 (file)
@@ -39,6 +39,7 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
 use TYPO3\CMS\Impexp\Domain\Repository\PresetRepository;
 use TYPO3\CMS\Impexp\Export;
@@ -532,7 +533,7 @@ class ImportExportController extends BaseScriptClass
                 $mimeType = 'application/octet-stream';
                 header('Content-Type: ' . $mimeType);
                 header('Content-Length: ' . strlen($out));
-                header('Content-Disposition: attachment; filename=' . basename($dlFile));
+                header('Content-Disposition: attachment; filename=' . PathUtility::basename($dlFile));
                 echo $out;
                 die;
             }
index 32c6806..e1c6622 100644 (file)
@@ -1584,7 +1584,7 @@ class Import extends ImportExport
         // Just for security, check again. Should actually not be necessary.
         if (!$bypassMountCheck) {
             try {
-                ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier(dirname($fileName));
+                ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier(PathUtility::dirname($fileName));
             } catch (InsufficientFolderAccessPermissionsException $e) {
                 $this->error('ERROR: Filename "' . $fileName . '" was not allowed in destination path!');
                 return false;
index 6036618..1642e79 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Utility\CommandUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * External standard parsers for indexed_search
@@ -521,7 +522,7 @@ class FileContentParser
                     unset($res);
                     $content = $this->pObj->convertHTMLToUtf8($content);
                     $contentArr = $this->pObj->splitHTMLContent($this->removeEndJunk($content));
-                    $contentArr['title'] = basename($absFile);
+                    $contentArr['title'] = PathUtility::basename($absFile);
                     $this->setLocaleForServerFileSystem(true);
                 }
                 break;
@@ -534,7 +535,7 @@ class FileContentParser
                     unset($res);
                     $content = $this->pObj->convertHTMLToUtf8($content);
                     $contentArr = $this->pObj->splitHTMLContent($this->removeEndJunk($content));
-                    $contentArr['title'] = basename($absFile);
+                    $contentArr['title'] = PathUtility::basename($absFile);
                     $this->setLocaleForServerFileSystem(true);
                 }
                 break;
@@ -571,7 +572,7 @@ class FileContentParser
                     $utf8_content = trim(strip_tags(str_replace('<', ' <', $content_xml)));
                     $contentArr = $this->pObj->splitRegularContent($utf8_content);
                     // Make sure the title doesn't expose the absolute path!
-                    $contentArr['title'] = basename($absFile);
+                    $contentArr['title'] = PathUtility::basename($absFile);
                     // Meta information
                     $cmd = $this->app['unzip'] . ' -p ' . escapeshellarg($absFile) . ' docProps/core.xml';
                     CommandUtility::exec($cmd, $res);
@@ -607,7 +608,7 @@ class FileContentParser
                     unset($res);
                     $utf8_content = trim(strip_tags(str_replace('<', ' <', $content_xml)));
                     $contentArr = $this->pObj->splitRegularContent($utf8_content);
-                    $contentArr['title'] = basename($absFile);
+                    $contentArr['title'] = PathUtility::basename($absFile);
                     // Make sure the title doesn't expose the absolute path!
                     // Meta information
                     $metaContent = GeneralUtility::xml2tree($meta_xml);
@@ -646,7 +647,7 @@ class FileContentParser
                 $contentCharset = 'utf-8';
                 $content = $this->pObj->convertHTMLToUtf8($content, $contentCharset);
                 $contentArr = $this->pObj->splitRegularContent($content);
-                $contentArr['title'] = basename($absFile);
+                $contentArr['title'] = PathUtility::basename($absFile);
                 // Make sure the title doesn't expose the absolute path!
                 $this->setLocaleForServerFileSystem(true);
                 break;
@@ -666,7 +667,7 @@ class FileContentParser
                 // Converting content:
                 $fileContent = $this->pObj->convertHTMLToUtf8(strip_tags(str_replace('<', ' <', $fileContent)), $charset);
                 $contentArr = $this->pObj->splitRegularContent($fileContent);
-                $contentArr['title'] = basename($absFile);
+                $contentArr['title'] = PathUtility::basename($absFile);
                 // Make sure the title doesn't expose the absolute path!
                 $this->setLocaleForServerFileSystem(true);
                 break;
@@ -686,7 +687,7 @@ class FileContentParser
                     $comment = '';
                 }
                 $contentArr = $this->pObj->splitRegularContent($comment);
-                $contentArr['title'] = basename($absFile);
+                $contentArr['title'] = PathUtility::basename($absFile);
                 // Make sure the title doesn't expose the absolute path!
                 $this->setLocaleForServerFileSystem(true);
                 break;
@@ -696,7 +697,7 @@ class FileContentParser
         // If no title (and why should there be...) then the file-name is set as title. This will raise the hits considerably if the search matches the document name.
         if (is_array($contentArr) && !$contentArr['title']) {
             // Substituting "_" for " " because many filenames may have this instead of a space char.
-            $contentArr['title'] = str_replace('_', ' ', basename($absFile));
+            $contentArr['title'] = str_replace('_', ' ', PathUtility::basename($absFile));
         }
         return $contentArr;
     }
index 9e1dbe4..c39c982 100644 (file)
@@ -20,6 +20,7 @@ use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 use TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility;
 
@@ -1134,7 +1135,7 @@ class Indexer
                 $cParts = $this->fileContentParts($ext, $absFile);
                 foreach ($cParts as $cPKey) {
                     $this->internal_log = [];
-                    $this->log_push('Index: ' . str_replace('.', '_', basename($file)) . ($cPKey ? '#' . $cPKey : ''), '');
+                    $this->log_push('Index: ' . str_replace('.', '_', PathUtility::basename($file)) . ($cPKey ? '#' . $cPKey : ''), '');
                     $Pstart = GeneralUtility::milliseconds();
                     $subinfo = ['key' => $cPKey];
                     // Setting page range. This is "0" (zero) when no division is made, otherwise a range like "1-3"
@@ -1619,7 +1620,7 @@ class Indexer
             'contentHash' => $content_md5h,
             'data_filename' => $file,
             'item_type' => $storeItemType,
-            'item_title' => trim($contentParts['title']) ?: basename($file),
+            'item_title' => trim($contentParts['title']) ?: PathUtility::basename($file),
             'item_description' => $this->bodyDescription($contentParts),
             'item_mtime' => $mtime,
             'item_size' => $size,
index e76e977..537965c 100644 (file)
@@ -23,6 +23,7 @@ use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
 use TYPO3\CMS\Core\Resource\StorageRepository;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Upgrade wizard which goes through all files referenced in backend_layout.icon
@@ -207,7 +208,7 @@ class BackendLayoutIconUpdateWizard extends AbstractUpdate
             $fileUid = null;
             $sourcePath = PATH_site . $this->sourcePath . $item;
             $targetDirectory = PATH_site . $fileadminDirectory . $this->targetPath;
-            $targetPath = $targetDirectory . basename($item);
+            $targetPath = $targetDirectory . PathUtility::basenameDuringBootstrap($item);
 
             // maybe the file was already moved, so check if the original file still exists
             if (file_exists($sourcePath)) {
index 3520094..eb1aef6 100644 (file)
@@ -24,6 +24,7 @@ use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
 use TYPO3\CMS\Core\Resource\StorageRepository;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Upgrade wizard which goes through all files referenced in fe_users::image
@@ -253,7 +254,7 @@ class FrontendUserImageUpdateWizard extends AbstractUpdate
             $fileUid = null;
             $sourcePath = PATH_site . $this->sourcePath . $item;
             $targetDirectory = PATH_site . $fileadminDirectory . $this->targetPath;
-            $targetPath = $targetDirectory . basename($item);
+            $targetPath = $targetDirectory . PathUtility::basename($item);
 
             // maybe the file was already moved, so check if the original file still exists
             if (file_exists($sourcePath)) {
index bebb1c2..3ef114e 100644 (file)
@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Install\UpgradeAnalysis;
 use TYPO3\CMS\Core\Registry;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Provide information about documentation files
@@ -237,7 +238,7 @@ class DocumentationFile
         $documentationFiles = [];
         if ($this->isRelevantDirectory($docDirectory, $version)) {
             $documentationFiles[$version] = [];
-            $absolutePath = strtr(dirname($docDirectory), '\\', '/') . '/' . $version;
+            $absolutePath = strtr(PathUtility::dirname($docDirectory), '\\', '/') . '/' . $version;
             $rstFiles = scandir($docDirectory);
             foreach ($rstFiles as $file) {
                 $fileInfo = pathinfo($file);
index a0acb38..ff208b2 100644 (file)
@@ -209,13 +209,13 @@ If you want to get more detailed information, use the --verbose option.')
                         $io->writeln('Keeping "' . $fileName . '" for record "' . $recReference . '"');
                     } else {
                         // Create unique name for file
-                        $newName = $fileFunc->getUniqueName(basename($fileName), dirname($absoluteFileName));
+                        $newName = $fileFunc->getUniqueName(PathUtility::basename($fileName), PathUtility::dirname($absoluteFileName));
                         $io->writeln('Copying "' . $fileName . '" to "' . PathUtility::stripPathSitePrefix($newName) . '" for record "' . $recReference . '"');
                         if (!$dryRun) {
                             GeneralUtility::upload_copy_move($absoluteFileName, $newName);
                             clearstatcache();
                             if (@is_file($newName)) {
-                                $error = $referenceIndex->setReferenceValue($hash, basename($newName));
+                                $error = $referenceIndex->setReferenceValue($hash, PathUtility::basename($newName));
                                 if ($error) {
                                     $io->error('ReferenceIndex::setReferenceValue() reported "' . $error . '"');
                                 }
index 5e263d8..6b90e79 100644 (file)
@@ -24,6 +24,7 @@ use TYPO3\CMS\Core\Core\Bootstrap;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\ReferenceIndex;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Finds files within uploads/ which are not needed anymore
@@ -203,7 +204,7 @@ If you want to get more detailed information, use the --verbose option.')
             }
 
             // If the file is a RTEmagic-image name and if so, we allow it
-            if (preg_match('/^RTEmagic[P|C]_/', basename($value))) {
+            if (preg_match('/^RTEmagic[P|C]_/', PathUtility::basenameDuringBootstrap($value))) {
                 continue;
             }
 
index 8497d5e..c6163d4 100644 (file)
@@ -227,7 +227,7 @@ If you want to get more detailed information, use the --verbose option.')
         // Traverse the files and put into a large table:
         while ($rec = $result->fetch()) {
             $file = $rec['ref_string'];
-            $filename = basename($file);
+            $filename = PathUtility::basenameDuringBootstrap($file);
             if (strpos($filename, 'RTEmagicC_') === 0) {
                 // First time the file is referenced => build index
                 if (!is_array($allRteImagesInUse[$file])) {
@@ -268,7 +268,7 @@ If you want to get more detailed information, use the --verbose option.')
         // Traverse files
         foreach ($files as $key => $value) {
             // If the file is a RTEmagic-image name
-            if (preg_match('/^RTEmagic[P|C]_/', basename($value))) {
+            if (preg_match('/^RTEmagic[P|C]_/', PathUtility::basenameDuringBootstrap($value))) {
                 $filesFound[] = $value;
                 continue;
             }
@@ -323,19 +323,19 @@ If you want to get more detailed information, use the --verbose option.')
                 if ($c === 0) {
                     $io->writeln('Keeping file ' . $fileName . ' for record ' . $recordID);
                 } else {
-                    $io->writeln('Copying file ' . basename($fileName) . ' for record ' . $recordID);
+                    $io->writeln('Copying file ' . PathUtility::basenameDuringBootstrap($fileName) . ' for record ' . $recordID);
                     // Get directory prefix for file and set the original name
-                    $dirPrefix = dirname($fileName) . '/';
-                    $rteOrigName = basename($fileInfo['original']);
+                    $dirPrefix = PathUtility::dirnameDuringBootstrap($fileName) . '/';
+                    $rteOrigName = PathUtility::basenameDuringBootstrap($fileInfo['original']);
                     // If filename looks like an RTE file, and the directory is in "uploads/", then process as a RTE file!
                     if ($rteOrigName && strpos($dirPrefix, 'uploads/') === 0 && @is_dir(PATH_site . $dirPrefix)) {
                         // From the "original" RTE filename, produce a new "original" destination filename which is unused.
                         $origDestName = $fileProcObj->getUniqueName($rteOrigName, PATH_site . $dirPrefix);
                         // Create copy file name
                         $pI = pathinfo($fileName);
-                        $copyDestName = dirname($origDestName) . '/RTEmagicC_' . substr(basename($origDestName), 10) . '.' . $pI['extension'];
+                        $copyDestName = PathUtility::dirnameDuringBootstrap($origDestName) . '/RTEmagicC_' . substr(PathUtility::basenameDuringBootstrap($origDestName), 10) . '.' . $pI['extension'];
                         if (!@is_file($copyDestName) && !@is_file($origDestName) && $origDestName === GeneralUtility::getFileAbsFileName($origDestName) && $copyDestName === GeneralUtility::getFileAbsFileName($copyDestName)) {
-                            $io->writeln('Copying file ' . basename($fileName) . ' for record ' . $recordID . ' to ' . basename($copyDestName));
+                            $io->writeln('Copying file ' . PathUtility::basenameDuringBootstrap($fileName) . ' for record ' . $recordID . ' to ' . PathUtility::basenameDuringBootstrap($copyDestName));
                             if (!$dryRun) {
                                 // Making copies
                                 GeneralUtility::upload_copy_move(PATH_site . $fileInfo['original'], $origDestName);
index a59e24e..bb7c6be 100644 (file)
@@ -115,8 +115,8 @@ class AdditionalResourceService implements SingletonInterface
     protected function resolvePath($resourcePath)
     {
         $absoluteFilePath = GeneralUtility::getFileAbsFileName($resourcePath);
-        $absolutePath = dirname($absoluteFilePath);
-        $fileName = basename($absoluteFilePath);
+        $absolutePath = PathUtility::dirname($absoluteFilePath);
+        $fileName = PathUtility::basename($absoluteFilePath);
 
         return PathUtility::getRelativePathTo($absolutePath) . $fileName;
     }