Task #68600
closedChange ResourceStorage::processUploadedFilename to sanitizeFileName
100%
Description
The method is not only for processing filenames of uploaded files but for all addFile actions. ResourceStorage::sanitizeFileName() better fits functionality and makes API more self explaining.
Updated by Andreas Wolf over 9 years ago
I think this whole method is a bit problematic:
1. The order of operations is wrong (I’m currently on correcting this, see below)
2. It emits a signal that is only used when the file is actually about to be added (PreFileAddSignal).
3. The folder check is unnecessary IMHO as the $targetFolder cannot be passed as NULL
4. Considering the original reason this method was added, I don’t see why a simple call to hasFileInFolder() did not suffice.
As for the signal, an API user might rely on the file only being emitted in addFile()—that implies that the file will actually be added moments later. If the file is not added at all in the current (AJAX) request, then things might break. There is documentation on that, but I’d rather have a dedicated signal than abusing a totally unrelated signal.
Concerning the order of operations: The first thing to do is let others alter the filename (via the signal), then the driver should tell if the filename is allowed (or correct it – sanitizeFileName()) and only then we must check the permissions.
Updated by Frans Saris over 9 years ago
Andreas Wolf wrote:
4. Considering the original reason this method was added, I don’t see why a simple call to hasFileInFolder() did not suffice.
The whole issue is that hasFileInFolder()
doesn't sanitize the input and also the signal can change the file name. So to check if a file already exists, f.i. when uploading a new file, you first need to sanitize the filename just like the normal addFile()
procedure would do. And this involves the driver->sanitize()
and the PreAddFile signal.
As for the signal, an API user might rely on the file only being emitted in addFile()—that implies that the file will actually be added moments later. If the file is not added at all in the current (AJAX) request, then things might break. There is documentation on that, but I’d rather have a dedicated signal than abusing a totally unrelated signal.
Maybe a new signal would indeed make sense, but current signal is currently documented in the code with:
// We do not care whether the file exists yet because $targetFileName may be changed by an
// external slot and only then we should check how to proceed according to $conflictMode
That's why we went for adjusting the current signal.
So your proposal is to go for a SanitizeFileName
Signal?
Updated by Frans Saris over 9 years ago
I'm not convinced that order is wrong. IMO sanitizeFileName()
should be called before the signal. Else the Signal gets the wrong filename.
Of Course the Signal could return an file that is not save. But that's the responsibility of the developer. When the filename is really passed to the driver to be created/added the driver sanitizes the filename one last time before creating the file and returns the filename.
Also the signal has a reference to the $driver
and is able to call $driver->sanitizeFileName()
.
So the order of operations is correct.
Updated by Benni Mack over 9 years ago
- Category changed from 1599 to File Abstraction Layer (FAL)
- Assignee deleted (
Benni Mack)
Updated by Frans Saris over 9 years ago
- Status changed from New to In Progress
- Assignee set to Frans Saris
Updated by Gerrit Code Review over 9 years ago
- Status changed from In Progress to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42116
Updated by Gerrit Code Review over 9 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42116
Updated by Gerrit Code Review over 9 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42116
Updated by Gerrit Code Review over 9 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42116
Updated by Gerrit Code Review over 9 years ago
Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42116
Updated by Gerrit Code Review over 9 years ago
Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42116
Updated by Gerrit Code Review over 9 years ago
Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42116
Updated by Gerrit Code Review over 9 years ago
Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42116
Updated by Frans Saris over 9 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 84218a9af555a9fca1a3e1e7f4414a858d7078db.
Updated by Riccardo De Contardi about 7 years ago
- Status changed from Resolved to Closed