Issue Bug Closed

#54357Inconsistent usage of filename sanitation

Alexander Stehlik 12/12/13, 13:53 updated 06/22/18, 23:36

Description

How would you solve this:

Before I create a file I check if the file exists in the folder where I want to create it:

\TYPO3\CMS\Core\Resource\Folder->hasFile()
\TYPO3\CMS\Core\Resource\ResourceStorage->hasFileInFolder()
\TYPO3\CMS\Core\Resource\Driver\AbstractDriver->fileExistsInFolder()

To add a file I use:

\TYPO3\CMS\Core\Resource\Folder->addFile()
\TYPO3\CMS\Core\Resource\ResourceStorage->addFile()
\TYPO3\CMS\Core\Resource\Driver\AbstractDriver->addFile()

The problem here is, that AbstractDriver->hasFile() will not call AbstractDriver->sanitizeFileName() before checking if the file exists, but add AbstractDriver->addFile() will do.

This will lead to the problem that addFile() can fail because the sanitized filename exists in the folder but not the file that was checked in the first place.

So basically I see two options:

  1. Make the sanitizeFilename() method publicly available (by changing the getDriver() in the ResourceStorage class to public and let the developers perform the sanitation manually or
  2. Add the sanitizeFileName() check to AbstractDriver->fileExistsInFolder()

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.