Skip to content

Commit 4f1db38

Browse files
committed
fix(export): remove new lines from form title in the exported filename
Signed-off-by: Thomas Citharel <[email protected]>
1 parent 683a519 commit 4f1db38

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/Service/FormsService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
*/
5757
class FormsService {
5858
private ?IUser $currentUser;
59-
59+
6060
public function __construct(
6161
IUserSession $userSession,
6262
private ActivityManager $activityManager,
@@ -780,6 +780,6 @@ public function getTemporaryUploadedFilePath(Form $form, Question $question): st
780780
}
781781

782782
private static function normalizeFileName(string $fileName): string {
783-
return str_replace(mb_str_split(\OCP\Constants::FILENAME_INVALID_CHARS), '-', $fileName);
783+
return str_replace([...mb_str_split(\OCP\Constants::FILENAME_INVALID_CHARS), "\n"], '-', $fileName);
784784
}
785785
}

tests/Unit/Service/FormsServiceTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,13 @@ public function testGetFileNameThrowsAnExceptionForInvalidFormat() {
14431443
$this->formsService->getFileName($form, 'dummy');
14441444
}
14451445

1446+
public function testGetFileNameThrowsAnExceptionForInvalid() {
1447+
$form = new Form();
1448+
$form->setTitle("Form \n new line");
1449+
1450+
$this->assertSame('Form - new line (responses).xlsx', $this->formsService->getFileName($form, 'xlsx'));
1451+
}
1452+
14461453
public function testGetFileName() {
14471454
$form = new Form();
14481455
$form->setTitle('Form 1');

0 commit comments

Comments
 (0)