From 2136098ebbb59157e1ec9c45ce8954b065b39d48 Mon Sep 17 00:00:00 2001 From: Jonas Rittershofer Date: Mon, 15 Feb 2021 16:28:38 +0100 Subject: [PATCH] Enclose all CSV fields Signed-off-by: Jonas Rittershofer --- docs/API.md | 8 ++++---- lib/Service/SubmissionService.php | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/API.md b/docs/API.md index d5eccd418..84d1e0285 100644 --- a/docs/API.md +++ b/docs/API.md @@ -397,9 +397,9 @@ Returns all submissions to the form in form of a csv-file. - Method: `GET` - Response: A Data Download Response containg the headers `Content-Disposition: attachment; filename="Form 1 (responses).csv"` and `Content-Type: text/csv;charset=UTF-8`. The actual data contains all submissions to the referred form, formatted as comma separated and escaped csv. ``` -"User display name",Timestamp,"Question 1","Question 2" -jonas,"Friday, January 22, 2021 at 12:47:29 AM GMT+0:00","Option 2",Answer -jonas,"Friday, January 22, 2021 at 12:45:57 AM GMT+0:00","Option 3",NextAnswer +"User display name","Timestamp","Question 1","Question 2" +"jonas","Friday, January 22, 2021 at 12:47:29 AM GMT+0:00","Option 2","Answer" +"jonas","Friday, January 22, 2021 at 12:45:57 AM GMT+0:00","Option 3","NextAnswer" ``` ### Export Submissions to Cloud (Files-App) @@ -501,4 +501,4 @@ This Error is not produed by the Forms-API, but comes from Nextclouds OCS API. T { "message": "CSRF check failed" } -``` \ No newline at end of file +``` diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index fb077999a..19191547e 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -42,6 +42,7 @@ use OCP\IUserManager; use OCP\IUserSession; +use League\Csv\EncloseField; use League\Csv\EscapeFormula; use League\Csv\Reader; use League\Csv\Writer; @@ -219,6 +220,7 @@ private function array2csv(array $header, array $records): string { $csv = Writer::createFromString(''); $csv->setOutputBOM(Reader::BOM_UTF8); $csv->addFormatter(new EscapeFormula()); + EncloseField::addTo($csv, "\t\x1f"); // insert the header $csv->insertOne($header);