Skip to content

Commit

Permalink
Get Us Closer to Csv Not Autodetect By Default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oleibman committed Dec 1, 2024
1 parent f37b119 commit c66ac56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/PhpSpreadsheet/Reader/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ class Csv extends BaseReader
*/
private static $constructorCallback;

/** Will be changed to false in next major release */
public const DEFAULT_TEST_AUTODETECT = true;

/**
* Attempt autodetect line endings (deprecated after PHP8.1)?
*/
private bool $testAutodetect = true;
private bool $testAutodetect = self::DEFAULT_TEST_AUTODETECT;

protected bool $castFormattedNumberToNumeric = false;

Expand Down
5 changes: 5 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Csv/CsvLineEndingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class CsvLineEndingTest extends TestCase
{
private string $tempFile = '';

private static bool $alwaysFalse = false;

protected function tearDown(): void
{
if ($this->tempFile !== '') {
Expand All @@ -32,6 +34,9 @@ public function testEndings(string $ending): void
$data = ['123', '456', '789'];
file_put_contents($filename, implode($ending, $data));
$reader = new Csv();
if (Csv::DEFAULT_TEST_AUTODETECT === self::$alwaysFalse) {
$reader->setTestAutoDetect(true);
}
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals($data[0], $sheet->getCell('A1')->getValue());
Expand Down

0 comments on commit c66ac56

Please sign in to comment.