From a5e64bb5f29367e072dfc984e775731c6b3dd8f4 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Gomez Date: Sat, 30 Apr 2022 11:03:03 +0200 Subject: [PATCH] Sanitized file name when uploading them to the library. ---- Saneados los nombres de archivos al subirlos a la biblioteca. --- Core/Model/AttachedFile.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Core/Model/AttachedFile.php b/Core/Model/AttachedFile.php index e125e651b0..8fe9e52542 100644 --- a/Core/Model/AttachedFile.php +++ b/Core/Model/AttachedFile.php @@ -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; }