Issue Bug Closed

#100683renameFile aborts if target file = original file, even if sanitizing the filename would result in different target filename

Sybille Peters 04/20/23, 13:25 updated 07/09/24, 12:56

Description

Currently, it is not possible to sanitize a file, simply be renaming it (to the current filename) because the function ResourceStorage::renameFile returns immediately if the new file name is the same as the old filename.

code:

public function renameFile($file, $targetFileName, $conflictMode = DuplicationBehavior::RENAME)
{
    // The name should be different from the current.
    if ($file->getName() === $targetFileName) {
        return $file;
    }
    $sanitizedTargetFileName = $this->driver->sanitizeFileName($targetFileName);

This leads to inconsistent behaviour.

Example:

  • Rename “ö.png” to “ö.png” results in “ö.png” (not sanitized)
  • but renaming “ö.png” to “ö1.png” result in “oe1.png”

The file should be renamed, if renaming it results in a different filename. This is the case if target filename = original filename, but sanitizedTargetFileName != originalfilename.

Also, if this behaviour were changed, it would be much easier to sanitize filenames. One just need to use the rename function.

## Versions

  • 11.5.26
  • main (12-dev)

Reviews 2

History 314

  1. Gerrit Code Review pushed patch set 1 for main to change 78766 status New Under Review 04/20/23, 13:35

  2. Gerrit Code Review pushed patch set 2 for main to change 78766 04/20/23, 13:36

  3. Gerrit Code Review pushed patch set 3 for main to change 78766 04/20/23, 13:37

  4. Sybille Peters changed description 04/20/23, 13:42

  5. Gerrit Code Review pushed patch set 4 for main to change 78766 04/20/23, 15:54

  6. Gerrit Code Review pushed patch set 5 for main to change 78766 04/23/23, 08:43

  7. Gerrit Code Review pushed patch set 6 for main to change 78766 05/03/23, 09:46

  8. Gerrit Code Review pushed patch set 7 for main to change 78766 05/12/23, 17:28

  9. Gerrit Code Review pushed patch set 8 for main to change 78766 05/31/23, 13:37

  10. Gerrit Code Review pushed patch set 9 for main to change 78766 07/05/23, 15:44

  11. Gerrit Code Review pushed patch set 10 for main to change 78766 07/05/23, 16:31

  12. Gerrit Code Review pushed patch set 1 for 12.4 to change 79787 07/06/23, 07:56

  13. Sybille Peters commented and changed status Under Review Resolved done 0 % 100 % 07/06/23, 08:00

    Applied in changeset commit:ec81e63db80acc8bb5477a3b0eed3d8fbcca97d1.

  14. Benni Mack changed status Resolved Closed 07/09/24, 12:56