Skip to content

Commit

Permalink
Sanitized file name when uploading them to the library.
Browse files Browse the repository at this point in the history
----
Saneados los nombres de archivos al subirlos a la biblioteca.
  • Loading branch information
NeoRazorX committed Apr 30, 2022
1 parent 47c1da7 commit a5e64bb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Core/Model/AttachedFile.php
Expand Up @@ -172,15 +172,16 @@ public function url(string $type = 'auto', string $list = 'List'): string
}
}

protected function fixFileName(string $orignal): string
protected function fixFileName(string $original): string
{
if (strlen($orignal) <= static::MAX_FILENAME_LEN) {
return (string)$orignal;
$fixed = self::toolBox()::utils()::noHtml($original);
if (strlen($fixed) <= static::MAX_FILENAME_LEN) {
return empty($fixed) ? '' : strtolower($fixed);
}

$parts = explode('.', strtolower($orignal));
$parts = explode('.', strtolower($fixed));
$extension = count($parts) > 1 ? end($parts) : '';
$name = substr($orignal, 0, static::MAX_FILENAME_LEN - strlen('.' . $extension));
$name = substr($fixed, 0, static::MAX_FILENAME_LEN - strlen('.' . $extension));
return $name . '.' . $extension;
}

Expand Down

0 comments on commit a5e64bb

Please sign in to comment.