From 1c1d65e8ba25cef5ca01ee4062e32c7573c93f14 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 c904269be..1ef116453 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -155,6 +155,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 fa468ff8d..5d8f60940 100644 --- a/lib/Service/FormsService.php +++ b/lib/Service/FormsService.php @@ -785,6 +785,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)); } }