Skip to content

Commit 8be52da

Browse files
committed
wip
1 parent 2c5d833 commit 8be52da

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/Forms/Exporters/CsvExporter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Statamic\Forms\Exporters;
44

5+
use League\Csv\EscapeFormula;
56
use League\Csv\Writer;
67
use SplTempFileObject;
78
use Statamic\Support\Arr;
@@ -15,6 +16,7 @@ public function export(): string
1516
{
1617
$this->writer = Writer::createFromFileObject(new SplTempFileObject);
1718
$this->writer->setDelimiter(Arr::get($this->config, 'delimiter', config('statamic.forms.csv_delimiter', ',')));
19+
$this->writer->addFormatter(new EscapeFormula);
1820

1921
$this->insertHeaders();
2022

tests/Forms/CsvExporterTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Tests\Forms;
4+
5+
use PHPUnit\Framework\Attributes\Test;
6+
use Statamic\Facades\Blueprint;
7+
use Statamic\Facades\Form;
8+
use Statamic\Facades\FormSubmission;
9+
use Statamic\Forms\Exporters\CsvExporter;
10+
use Tests\PreventSavingStacheItemsToDisk;
11+
use Tests\TestCase;
12+
13+
class CsvExporterTest extends TestCase
14+
{
15+
use PreventSavingStacheItemsToDisk;
16+
17+
#[Test]
18+
public function it_neutralizes_formula_injection_in_submission_values()
19+
{
20+
$blueprint = Blueprint::makeFromFields(['name' => ['type' => 'text']]);
21+
Blueprint::shouldReceive('find')->with('forms.test')->andReturn($blueprint);
22+
23+
$form = tap(Form::make('test'))->save();
24+
FormSubmission::make()->form($form)->data(['name' => '=1+1'])->save();
25+
26+
$csv = (new CsvExporter)->setForm($form)->setConfig([])->export();
27+
28+
$this->assertStringContainsString('\'=1+1', $csv);
29+
$this->assertStringNotContainsString('"=1+1', $csv);
30+
}
31+
}

0 commit comments

Comments
 (0)