Skip to content

Commit c66ac56

Browse files
committed
Get Us Closer to Csv Not Autodetect By Default
This has been requested a few times, most recently issue PHPOffice#4092. Because it's a breaking change, I haven't proceeded with it. But, because I have a breaking change PR PHPOffice#4240 already in the queue, this gives a plan for getting where we want to go (under the extremely likely assumption that most users don't deal with Csv files with Mac line endings). This PR doesn't change the current behavior, but it gets us to a state where a single-line change will be sufficient when the time comes for a new major release.
1 parent f37b119 commit c66ac56

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/PhpSpreadsheet/Reader/Csv.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@ class Csv extends BaseReader
8484
*/
8585
private static $constructorCallback;
8686

87+
/** Will be changed to false in next major release */
88+
public const DEFAULT_TEST_AUTODETECT = true;
89+
8790
/**
8891
* Attempt autodetect line endings (deprecated after PHP8.1)?
8992
*/
90-
private bool $testAutodetect = true;
93+
private bool $testAutodetect = self::DEFAULT_TEST_AUTODETECT;
9194

9295
protected bool $castFormattedNumberToNumeric = false;
9396

tests/PhpSpreadsheetTests/Reader/Csv/CsvLineEndingTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class CsvLineEndingTest extends TestCase
1212
{
1313
private string $tempFile = '';
1414

15+
private static bool $alwaysFalse = false;
16+
1517
protected function tearDown(): void
1618
{
1719
if ($this->tempFile !== '') {
@@ -32,6 +34,9 @@ public function testEndings(string $ending): void
3234
$data = ['123', '456', '789'];
3335
file_put_contents($filename, implode($ending, $data));
3436
$reader = new Csv();
37+
if (Csv::DEFAULT_TEST_AUTODETECT === self::$alwaysFalse) {
38+
$reader->setTestAutoDetect(true);
39+
}
3540
$spreadsheet = $reader->load($filename);
3641
$sheet = $spreadsheet->getActiveSheet();
3742
self::assertEquals($data[0], $sheet->getCell('A1')->getValue());

0 commit comments

Comments
 (0)