Skip to content

Commit

Permalink
Enclose all CSV fields
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
  • Loading branch information
jotoeri committed Feb 22, 2021
1 parent f283748 commit 2136098
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -501,4 +501,4 @@ This Error is not produed by the Forms-API, but comes from Nextclouds OCS API. T
{
"message": "CSRF check failed"
}
```
```
2 changes: 2 additions & 0 deletions lib/Service/SubmissionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2136098

Please sign in to comment.