Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(export): remove new lines from form title in the exported filename #2343

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading