Skip to content

Commit

Permalink
fix(export): remove new lines from form title in the exported filename
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld committed Oct 4, 2024
1 parent a692d13 commit 7443df3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Service/FormsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
*/
class FormsService {
private ?IUser $currentUser;

public function __construct(
IUserSession $userSession,
private ActivityManager $activityManager,
Expand Down Expand Up @@ -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);
}
}
7 changes: 7 additions & 0 deletions tests/Unit/Service/FormsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 7443df3

Please sign in to comment.