From f17fc993ae294f73b4a672081490d5e2629b3008 Mon Sep 17 00:00:00 2001 From: Kostiantyn Miakshyn Date: Thu, 23 Jan 2025 02:03:30 +0100 Subject: [PATCH] fix: Improve compatibility with Windows for uploaded files Signed-off-by: Kostiantyn Miakshyn --- lib/Constants.php | 13 +++++++++++++ lib/Service/FormsService.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Constants.php b/lib/Constants.php index 1726d7dc9..6a9e22455 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -175,6 +175,19 @@ class Constants { 'x-office/spreadsheet', ]; + public const FILENAME_INVALID_CHARS = [ + "\n", + '/', + '\\', + ':', + '*', + '?', + '"', + '<', + '>', + '|', + ]; + /** * !! Keep in sync with src/mixins/ShareTypes.js !! */ diff --git a/lib/Service/FormsService.php b/lib/Service/FormsService.php index 8683d7029..f95b60017 100644 --- a/lib/Service/FormsService.php +++ b/lib/Service/FormsService.php @@ -777,6 +777,6 @@ public function getTemporaryUploadedFilePath(Form $form, Question $question): st } private static function normalizeFileName(string $fileName): string { - return str_replace([...mb_str_split(\OCP\Constants::FILENAME_INVALID_CHARS), "\n"], '-', $fileName); + return trim(str_replace(Constants::FILENAME_INVALID_CHARS, '-', $fileName)); } }