diff --git a/lib/Service/FormsService.php b/lib/Service/FormsService.php index a1c6fb6d6..386a4f727 100644 --- a/lib/Service/FormsService.php +++ b/lib/Service/FormsService.php @@ -56,7 +56,7 @@ */ class FormsService { private ?IUser $currentUser; - + public function __construct( IUserSession $userSession, private ActivityManager $activityManager, @@ -780,6 +780,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), '-', $fileName); + return str_replace([...mb_str_split(\OCP\Constants::FILENAME_INVALID_CHARS), "\n"], '-', $fileName); } } diff --git a/tests/Unit/Service/FormsServiceTest.php b/tests/Unit/Service/FormsServiceTest.php index b58fb81df..349331179 100644 --- a/tests/Unit/Service/FormsServiceTest.php +++ b/tests/Unit/Service/FormsServiceTest.php @@ -1445,6 +1445,13 @@ public function testGetFileNameThrowsAnExceptionForInvalidFormat() { $this->formsService->getFileName($form, 'dummy'); } + public function testGetFileNameReplacesNewLines() { + $form = new Form(); + $form->setTitle("Form \n new line"); + + $this->assertSame('Form - new line (responses).xlsx', $this->formsService->getFileName($form, 'xlsx')); + } + public function testGetFileName() { $form = new Form(); $form->setTitle('Form 1');